In mathematics the Fibonacci numbers are a sequence of numbe

In mathematics, the Fibonacci numbers are a sequence of numbers, where each number is the sum of the previous two. The first two numbers of the Fibonacci sequence are 0 and 1. So, the Fibonacci sequence has the following form: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144... Please write a MATLAB script file that finds the 50th number in this Fibonacci sequence. What is the number MATLAB finds

Solution

The code that I have so far is

N=input(\'Pick a number\ \');
fib=zeros(1:N);
fib(1)=1;
fib(2)=1;
k=3;
while k <= N
    fib(k)=fib(k-2)+fib(k-1);
    k=k+1;
end


fprintf(\'The Fibonacci sequence to %d terms is %g \ \',N,fib);

However now it will depend on the value of n.

However the result I get from this is:
The Fibonacci sequence to 0 terms is 0

Or we can say like this also..

The equation for calculating the Fibonacci numbers is

f(n) = f(n-1) + f(n-2)
knowing that
f(0) = 1 and f(1) = 1

The simple code that I wrote is

 In mathematics, the Fibonacci numbers are a sequence of numbers, where each number is the sum of the previous two. The first two numbers of the Fibonacci seque

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site