Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The Fibonacci Sequence is a mathematical sequence which occurs throughout nature

ID: 3567872 • Letter: T

Question

The Fibonacci Sequence is a mathematical sequence which occurs throughout nature as well as in music, art and popular culture. The Fibonacci Sequence are the following numbers in the integer sequence 0,1,1,2,3,5,8,13,21,34,55,89. . . . The definition for Fibonacci Sequence is as follows, Fn=Fn-1 + Fn-2 where F0=0,F1=1 Write a function named fibonacci which takes one input X which is a non-negative integer(s) and returns the Xth fibonacci number in the fibonacci sequence. If X is a vector or matrix, the output is a vector or matrix of the same size as the input with fibonacci numbers of the corresponding elements of the input.

Explanation / Answer

function [y]=fibonacci(x)
[m n]=size(x);
a=max(max(x));
f_seq=zeros(1,a);
for i=1:a
if i==1 || i==2
f_seq(i)=1;

else
f_seq(i)=f_seq(i-1)+f_seq(i-2);

end
end
y=zeros(m,n);
for i=1:m
for j=1:n
y(i,j)=f_seq(x(i,j));
end
end
end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote