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

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
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
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 07/13/2008 for the course MAE 105 taught by Professor Neiman-nassat during the Spring '07 term at UCSD.

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 Right Arrow Icon
Ask a homework question - tutors are online