{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# HW1 - HW 1 Problem 1 Contents Problem description fib.m(a...

This preview shows pages 1–4. Sign up to view the full content.

HW 1 Problem 1 Contents Problem description fib.m (a) Print out the first 10 Fibonacci numbers (b) Print out the ratio F(n+1) / F(n) for the first 25 Fibonacci numbers Convergence to golden ratio? Problem description Use the function fib (stored in fib.m) to compute and display the first 10 Fibonacci numbers fib.m An important part of this Problem is the function to compute the n-th Fibonacci number. This is stored in the file fib.m type fib.m % Function to compute the n-th Fibonacci number function f = fib(n) if (n < 2) % if n is less than 2, return 1 f = 1; else % otherwise, recursively call fib f = fib(n-1) + fib(n-2); end end (a) Print out the first 10 Fibonacci numbers for n = 1:10 disp(fib(n)) end 1 2 3 5 8

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
13 21 34 55 89 (b) Print out the ratio F(n+1) / F(n) for the first 25 Fibonacci numbers We also store the ratio corresponding to n in ratio(n) for n = 2:25 ratio(n) = fib(n+1) / fib(n); disp(ratio(n)) end 1.5000 1.6667 1.6000 1.6250 1.6154 1.6190 1.6176 1.6182 1.6180 1.6181 1.6180 1.6180 1.6180 1.6180 1.6180 1.6180 1.6180
1.6180 1.6180 1.6180 1.6180 1.6180 1.6180 1.6180 Convergence to golden ratio? Lets plot the values of the ratios of Fibonacci numbers together with Kepler's golden ratio, and see if we get good convergence % Compute Kepler's Golden Ratio golden = (1 + sqrt(5)) / 2 figure; hold on; plot(ratio, 'o-') plot(golden * ones(1,length(ratio)), 'g') legend('F(n+1) / F(n)', 'Golden Ratio', 'Location', 'Southeast') xlabel('n') golden = 1.6180 HW 1 Problem 2 Contents Problem description Define delta_x and x

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 10

HW1 - HW 1 Problem 1 Contents Problem description fib.m(a...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online