Fibonacci numbers are the numbers in a sequence in which the

Fibonacci numbers are the numbers in a sequence in which the first two elements are 0 and 1, and the value of each subsequent element is the sum of the previous two elements: 0, 1, 1, 2, 3, 5, 8, 13, ... Write a MATLAB function the outputs the first N Fibonacci numbers, for any number N. The function should accept a single input N and returns an output array containing the sequence of N numbers. Develop the MATLAB function that returns a Fibonacci sequence of numbers in which the last number in the sequence is less than or equal to the number K, specified as an input to the function.

Solution

MATLAB SCRIPT CODE (BONUS INCLUDED)

clc
clear all
%to get n fibonacci numbers
N=input(\'Pick a number\ \');
fib=zeros(1,N);
fib(1)=1;
fib(2)=1;
k=3;
maxFibNumber=input(\'enter the value of maxfiber no=\');
while k <= N
fib(k)=fib(k-2)+fib(k-1);
  
if fib(k) >= maxFibNumber
break;
end
k=k+1;
end

 Fibonacci numbers are the numbers in a sequence in which the first two elements are 0 and 1, and the value of each subsequent element is the sum of the previou

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site