Matlab Help The nth Fibonacci number is defined by the foll
Matlab Help :
The nth Fibonacci number is defined by the following recursive equations: f(l) = 0; f(2) = 1; f(n) = f(n-l) + f(n-2) Therefore the 3^rd Fibonacci number is calculated: f(3)=f(2)+f(l)=l+0=l, and so forth for higher numbers. Write a function file to calculate nth Fibonacci number; n is an integer input to the function file and the Fibonacci number is the output argument. Use a for loop to perform the calculation.Solution
Here is the matlab code that prints fibonacci number for given input n.
n=input(\'Pick a number\ \');
%fib=zeros(1:n);
fib(1)=1;
fib(2)=1;
k=3;
for k=3:n
fib(k)=fib(k-2)+fib(k-1);
end
fprintf(\'The Fibonacci Value of %d th element is %d \ \',n,fib(k));
