This needs to be written in matlab. Thanks In mathematics, the Fibonacci numbers
ID: 2073495 • Letter: T
Question
This needs to be written in matlab.
Thanks
In mathematics, the Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and characterized by the fact that every number in it is the sum of the two preceding ones [wikipedia). 1, 1,2,3,5, 8, 13, 21,34, 55, 89, 144, n-1 n-2 Write a function to calculate the nth Fibonacci number. Examples: Input n = 5 Output is 5 Input n = 7 Output is 13 Your Function C Reset MATLAB Documentation 1 function fibnum -fib(n) 2 3 % n is an input % fibnum is an output, representing the Fibonacci number % Names of vairalbes (fibnum, n) can be changed. The name of function (fib) and the order of the variables cannot. fibnum = 6 endExplanation / Answer
CODE:
function fibnum=fib(n)
fibonum1=0;
fibonum2=1;
for i=1:n-1
fibonum=fibonum1+fibonum2;
fibonum1=fibonum2;
fibonum2=fibonum;
end
disp(fibonum)
OUTPUT EXAMPLE:(FOR n=9)
fib(9)
34
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.