Professional Documents
Culture Documents
1. TUTORIAL PROBLEMS
1. Let |h| < 1. Which of the following functions are O(h)? Explain why.
(a) 2h, (b) −4h, (c) h+h2 , (d) −3h+h3 , (e) |h|1/2 , (f) |h|1/2 +h3 , (g) h+sin h,
(h) h + cos h.
2. MATLAB PROGRAMMING
F0 = 1, F1 = 1, Fk+2 = Fk+1 + Fk , k ≥ 1.
1
The following Matlab function produces the first n Fibonacci numbers
function f=fibonacci(n) % Fibonacci sequence
% f=fibonacci(n) generates the first n Fibonacci numbers
f=zeros(n,1); % assign an n-by-1 zero vector to f
f(1)=1;
f(2)=1;
for k=3:n
f(k)=f(k-1)+f(k-2);
end;
Task 1. Make a file called fibonacci.m and store this code in that file.
Then call the function
f=fibonacci(20)
to print the first 20 Fibonacci numbers.
Task 2. Modify the code to compute the ratio Fk+1 /Fk and print this
ratio on the screen for k = 3, 4, . . . , n. Note that
√
Fk+1 1+ 5
lim = .
k→∞ Fk 2
Task 3. (Do if you have time) Modify the code to compute the first n
Fibonacci numbers using the while loop instead.