rss
Twitter Delicious Facebook Digg Stumbleupon Favorites
Showing posts with label series. Show all posts
Showing posts with label series. Show all posts

Sunday, October 9, 2011

A program to generate Harmonic Series


In mathematics, the harmonic series is the divergent infinite series:
\sum_{n=1}^\infty\,\frac{1}{n} \;\;=\;\; 1 \,+\, \frac{1}{2} \,+\, \frac{1}{3} \,+\, \frac{1}{4} \,+\, \frac{1}{5} \,+\, \cdots.\!
Its name derives from the concept of overtones, or harmonics in music: the wavelengths of the overtones of a vibrating string are 1/2, 1/3, 1/4, etc., of the string's fundamental wavelength. Every term of the series after the first is the harmonic mean of the neighboring terms; the term harmonic mean likewise derives from music.
The fact that the harmonic series diverges was first proven in the 14th century by Nicole Oresme, but this achievement fell into obscurity. Proofs were given in the 17th century by Pietro Mengoli,Johann Bernoulli, and Jakob Bernoulli.
Historically, harmonic sequences have had a certain popularity with architects. This was so particularly in the Baroque period, when architects used them to establish the proportions of floor plans, ofelevations, and to establish harmonic relationships between both interior and exterior architectural details of churches and palaces.
The harmonic series is counterintuitive to students first encountering it, because it is a divergent series though the limit of the nth term as n goes to infinity is zero. The divergence of the harmonic series is also the source of some apparent paradoxes. One example of these is the "worm on the rubber band". Suppose that a worm crawls along a 1 meter rubber band and, after each minute, the rubber band is uniformly stretched by an additional 1 meter. If the worm travels 1 centimeter per minute, will the worm ever reach the end of the rubber band? The answer, counterintuitively, is "yes", for after n minutes, the ratio of the distance travelled by the worm to the total length of the rubber band is
\frac{1}{100}\sum_{k=1}^n\frac{1}{k}.
Because the series gets arbitrarily large as n becomes larger, eventually this ratio must exceed 1, which implies that the worm reaches the end of the rubber band. The value of n at which this occurs must be extremely large, however, approximately e100, a number exceeding 1040. Although the harmonic series does diverge, it does so very slowly.
Another example is: given a collection of identical dominoes, it is clearly possible to stack them at the edge of a table so that they hang over the edge of the table. The counterintuitive result is that one can stack them in such a way as to make the overhang arbitrarily large, provided there are enough dominoes.

class Harmonic{
      public static void main(String args[]){
      int num = Integer.parseInt(args[0]);
      double result = 0.0;
      while(num > 0){
            result = result + (double) 1 / num;
            num--;
      }
      System.out.println("Output of Harmonic Series is "+result);
  }
}

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;
          }
   }
}
Powered by Blogger.