Description Usage Arguments Value Functions FibSeq FibStart FibNext Examples
This is a solution to Euler problem 2.
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
1 2 3 4 5 6 7 |
x |
an integer number for which the following number in the Fibonacci sequence will be generated \loadmathjax |
lim |
a length limit of the Fibonacci sequence to return |
value |
a maximum value of the Fibonacci sequence to calculate to |
a double vector
fibSeq
: a function to generate the Fibonacci sequence
fibStart
: a function to generate the beginning of the Fibonacci sequence
fibNext
: a function to generate the next number in a Fibonacci sequence
This function does not discriminate against starting integers. This means any number may be input
as x
and a Fibonacci-like sequence will be calculated from that starting point. The actual
Fibonacci sequence will only be generated by inputting a number actually in the Fibonacci sequence.
This function generates the first three numbers of the Fibonacci sequence as necessary (0, 1, 1). This is necessary because these numbers can not be generated by utilizing the golden ratio (see fibNext for further detail). If given a number other than 0 or 1, this function will simply return that number.
This function generates the next number of the Fibonacci sequence given a preceding number, x
.
The ratio of any two consecutive entries in the Fibonacci sequence rapidly approaches \mjeqn\varphiascii.
x
is multipled by \mjeqn\varphiascii and rounded to the nearest integer to obtain the next number in sequence.
Note this will not give the correct next number if x = 0
or x = 1
.
=\frac1+\sqrt52 ascii
1 2 3 4 5 6 7 8 9 10 |
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.