SuanShu, a Java numerical and statistical library

com.numericalmethod.suanshu.analysis.sequence
Class Fibonacci

java.lang.Object
  extended by com.numericalmethod.suanshu.analysis.sequence.Fibonacci
All Implemented Interfaces:
Sequence

public class Fibonacci
extends java.lang.Object
implements Sequence

Construct a Fibonacci sequence.

A Fibonacci sequence starts with 0 and 1 as the first two numbers. Each subsequent number is the sum of the previous two.

For example, 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

See Also:
Wikipedia: Fibonacci number

Field Summary
 int length
          length of the sequence
 
Constructor Summary
Fibonacci(int length)
          Construct a Fibonacci sequence.
 
Method Summary
 double get(int index)
          Get the index-th Fibonacci number, counting from 1.
 double[] getAll()
          Get the whole (finite) sequence in a double[] array.
 int length()
          Get the number of computed terms in the sequence.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

length

public int length
length of the sequence

Constructor Detail

Fibonacci

public Fibonacci(int length)
Construct a Fibonacci sequence.

Parameters:
length - the number of terms to generate
Method Detail

length

public int length()
Description copied from interface: Sequence
Get the number of computed terms in the sequence.

Specified by:
length in interface Sequence
Returns:
the length of sequence

get

public double get(int index)
Get the index-th Fibonacci number, counting from 1.

Specified by:
get in interface Sequence
Parameters:
index - an index ≤ length
Returns:
the index-th Fibonacci number

getAll

public double[] getAll()
Get the whole (finite) sequence in a double[] array. Get the first length Fibonacci numbers in a double[] array.

Specified by:
getAll in interface Sequence
Returns:
the first length Fibonacci numbers

SuanShu, a Java numerical and statistical library

Copyright © 2011 Numerical Method Inc. Ltd. All Rights Reserved.