|
|

楼主 |
发表于 22-10-2009 03:49 PM
|
显示全部楼层
QUESTION 3
The Fibonaccinumbers 0, 1, 1, 2, 3, 5, 8, 13, 21 . . . are defined by
f1
= 0
f2
= 1
fk = fk−2
+ fk−1
for k≥3.
Matlab function, named as compute_last_fibonacci,which computes the Fibonacci numbers up to a given value n and returnsthe last element of these numbers. If n is a negative number thefunction should return -1 is given as follows.
function last =compute_last_fibonacci(n)
last = -1;
if (n>=0)
f = [ 0 1 ];
for k=3:n
f(k) = f(k-2) + f(k-1);
end
last = f(k);
end;
Executethe above function for five different
input values and display the result.
Answer: paste your matlab commands and outputs here. |
|