. (20 points) A Fibonacci sequence is generated by adding two previous values to
ID: 3703328 • Letter: #
Question
. (20 points) A Fibonacci sequence is generated by adding two previous values together to obtain a new value: where subscript "n" refers to the term number. This sequence always starts with F10, and F2 1. (For example, for n 8 total terms, the sequence would be 0,1. 1.2, 3, 5, 8, 13.) F,?????Fa F8 Complete the following MATLAB script that fills a vector, E, with each successive value of a Fibonacci sequence. The first and second values in the vector F have already been initialized to 0 and 1, respectively. Ask the user to input a positive integer, and use a while loop to add Fibonacci values to the vector, F, while the values are less than the user input value. Finally, use fprintf to display a descriptive message that includes the total number o erms in the Fibonacci sequence generate % Problem 1-Fibonacci F(2) 1Explanation / Answer
#Matlab script that prompts n value and then print the fibbonacci numbers
#Intialize F(0) and F(1) values
F(1)=0;
F(2)=1;
i = 3;
#read n value
n =input('Enter n-value ');
#print starting two numbers
fprintf('%5d',F(1));
fprintf('%5d',F(2));
#generate fibonacci numbers
while (i <= n)
F(i) = F(i-1) + F(i-2);
fprintf('%5d',F(i));
i = i + 1;
end
#print number of fibb numbers
fprintf(' Number of fibbonacci numbers : %5d ',i-1);
Sample Output:
?
Enter n-value 7
0 1 1 2 3 5 8
Number of fibbonacci numbers : 7
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.