MATLAB: ibone sputed ordng te the toiiotg En = Fn-1 + Fn-2 with Fo F1 1. a. Comp
ID: 3588679 • Letter: M
Question
MATLAB:
ibone sputed ordng te the toiiotg En = Fn-1 + Fn-2 with Fo F1 1. a. Compute the first 10 Fibonacci numbers b. For the first 50 Fibonacci numbers, compute the ratio FR Fn-1 sqrt (5))/2. What do your results show? In the following exercises use the dot operator where appropriate: 9. Given the array A = [2 7 9 7 ; 3 1 5 6 ; 8 1 2 5], provide the command that will a. assign the even-numbered columns of A to an array called B b. assign the odd-numbered rows to an array called C c. convert A into a 4-by-3 array (using reshape) d. compute the reciprcal of each element of A e. compute the square-root of each element of AExplanation / Answer
5) Code :
function f = fibonacci(n)
if (n==1)
f= 1;
elseif (n==2)
f = 1;
else
f = fibonacci(n-1) + fibonacci(n-2);
end
end
Save the above code as fibonacci.m
and then run the following code :
5) (a)
for i=1:10
fibonacci(i)
end
OUTPUT
ans =
1
ans =
1
ans =
2
ans =
3
ans =
5
ans =
8
ans =
13
ans =
21
ans =
34
ans =
55
5) (b)
Run this code :
for i=2:50
ratio=fibonacci(i)/fibonacci(i-1)
end
OUTPUT :
ratio =
1
ratio =
2
ratio =
1.5000
ratio =
1.6667
ratio =
1.6000
ratio =
1.6250
ratio =
1.6154
ratio =
1.6190
ratio =
1.6176
ratio =
1.6182
ratio =
1.6180
ratio =
1.6181
ratio =
1.6180
ratio =
1.6180
ratio =
1.6180
ratio =
1.6180
ratio =
1.6180
ratio =
1.6180
ratio =
1.6180
ratio =
1.6180
ratio =
1.6180
ratio =
1.6180
ratio =
1.6180
ratio =
1.6180
ratio =
1.6180
ratio =
1.6180
ratio =
1.6180
ratio =
1.6180
ratio =
1.6180
ratio =
1.6180
ratio =
1.6180
ratio =
1.6180
And,
(1+sqrt(5))/2
ans =
1.6180
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.