Page 42 -
P. 42
From the above, it is then straightforward to compute the first few
Fibonacci numbers:
1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, …
Example 2.1
Write a program for finding the first 20 Fibonacci numbers.
Solution: The following program fulfills this task:
N=18;
F(1)=1;
F(2)=1;
for k=1:N
F(k+2)=F(k)+F(k+1);
end
F
It should be noted that the value of the different elements of the sequence
depends on the values of the initial conditions, as illustrated in Pb. 2.1, which
follows.
In-Class Exercises
Pb. 2.1 Find the first 20 elements of the sequence that obeys the same recur-
sion relation as that of the Fibonacci numbers, but with the following initial
conditions:
F(1) = 0.5 and F(2) = 1
Pb. 2.2 Find the first 20 elements of the sequence generated by the follow-
ing difference equation:
F(k + 3) = F(k) + F(k + 1) + F(k + 2)
with the following boundary conditions:
F(1) = 1, F(2) = 2, and F(3) = 3
Why do we need to specify three initial conditions?
© 2001 by CRC Press LLC