rss
Twitter Delicious Facebook Digg Stumbleupon Favorites

Friday, October 7, 2011

A program to find Fibonacci series of a given number.

In mathematics, the Fibonacci numbers are the numbers in the following integer sequence:
0,\;1,\;1,\;2,\;3,\;5,\;8,\;13,\;21,\;34,\;55,\;89,\;144,\; \ldots\;
By definition, the first two Fibonacci numbers are 0 and 1, and each subsequent number is the sum of the previous two.
In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation
F_n = F_{n-1} + F_{n-2},\!\,
with seed values
F_0 = 0 \quad\text{and}\quad F_1 = 1.
The Fibonacci sequence is named after Leonardo of Pisa, who was known as Fibonacci. Fibonacci's 1202 book Liber Abaci introduced the sequence to Western European mathematics,although the sequence had been described earlier in Indian mathematics. (By modern convention, the sequence begins with F0 = 0. The Liber Abaci began the sequence with F1 = 1, omitting the initial 0, and the sequence is still written this way by some.)
Fibonacci numbers are closely related to Lucas numbers in that they are a complementary pair of Lucas sequences. They are intimately connected with the golden ratio, for example the closest rational approximations to the ratio are 2/1, 3/2, 5/3, 8/5, ... . Applications include computer algorithms such as the Fibonacci search technique and the Fibonacci heap data structure, and graphs called Fibonacci cubes used for interconnecting parallel and distributed systems. They also appear in biological settings, such as branching in trees, arrangement of leaves on a stem, the fruit spouts of a pineapple, the flowering of artichoke, an uncurling fern and the arrangement of a pine cone.
The Fibonacci sequence appears in Indian mathematics, in connection with Sanskrit prosody. In the Sanskrit oral tradition, there was much emphasis on how long (L) syllables mix with the short (S), and counting the different patterns of L and S within a given fixed length results in the Fibonacci numbers; the number of patterns that are m short syllables long is the Fibonacci number Fm + 1.
Susantha Goonatilake writes that the development of the Fibonacci sequence "is attributed in part to Pingala (200 BC), later being associated with Virahanka (c. 700 AD), Gopāla (c.1135 AD), and Hemachandra (c.1150)". Parmanand Singh cites Pingala's cryptic formula misrau cha ("the two are mixed") and cites scholars who interpret it in context as saying that the cases for m beats (Fm+1) is obtained by adding a [S] to Fm cases and [L] to the Fm−1 cases. He dates Pingala before 450 BCE.

However, the clearest exposition of the series arises in the work of Virahanka (c. 700AD), whose own work is lost, but is available in a quotation by Gopala (c.1135):
Variations of two earlier meters [is the variation]... For example, for [a meter of length] four, variations of meters of two [and] three being mixed, five happens. [works out examples 8, 13, 21]... In this way, the process should be followed in all mAtrA-vr.ttas (prosodic combinations).
The series is also discussed by Gopala (before 1135AD) and by the Jain scholar Hemachandra (c. 1150AD).
In the West, the Fibonacci sequence first appears in the book Liber Abaci (1202) by Leonardo of Pisa, known as Fibonacci. Fibonacci considers the growth of an idealized (biologically unrealistic)rabbit population, assuming that: a newly born pair of rabbits, one male, one female, are put in a field; rabbits are able to mate at the age of one month so that at the end of its second month a female can produce another pair of rabbits; rabbits never die and a mating pair always produces one new pair (one male, one female) every month from the second month on. The puzzle that Fibonacci posed was: how many pairs will there be in one year?
  • At the end of the first month, they mate, but there is still only 1 pair.
  • At the end of the second month the female produces a new pair, so now there are 2 pairs of rabbits in the field.
  • At the end of the third month, the original female produces a second pair, making 3 pairs in all in the field.
  • At the end of the fourth month, the original female has produced yet another new pair, the female born two months ago produces her first pair also, making 5 pairs.
At the end of the nth month, the number of pairs of rabbits is equal to the number of new pairs (which is the number of pairs in month n − 2) plus the number of pairs alive last month (n − 1). This is thenth Fibonacci number.
The name "Fibonacci sequence" was first used by the 19th-century number theorist Édouard Lucas.

 
class FibonacciSeries{
      public static void main(String args[]){
          int num = Integer.parseInt(args[0]);               
          System.out.println("*****Fibonacci Series*****");
          int f1, f2=0, f3=1;
          for(int i=1;i<=num;i++){
             System.out.println(" "+f3+" ");
             f1 = f2;
             f2 = f3;
             f3 = f1 + f2;
          }
   }
}

0 comments:

Post a Comment

Powered by Blogger.