The Fibonacci numbers are a sequence of numbers where each n
The Fibonacci numbers are a sequence of numbers, where each number is the sum of the previous two. Here is part of the sequence
0,1,1,2,3,5,8,13,24,34,55,89,144.......
1. Please write a MATLAB script file that finds the 50th number in this Fibonacci sequence. What is the number MATLAB finds?
2. Please write a MATLAB program that calculates the summation of the first 50 numbers from the sequence.
Solution
1. script for first program:
%Clear screen and memory
clear; clc; format compact
% Initialize the first two values
f(1) = 0;
f(2) = 1;
disp (f(1))
disp (f(2))
% Create the next 50 Fibonacci numbers
for i = 3 : 50
% Perform the sum of terms accordingly
f(i) = f(i-1) + f(i-2);
disp(f(i))
end
2. program to find the sum of first 50 numbers of the sequence:
%Clear screen and memory
clear; clc; format compact
% Initialize the first two values
f(1) = 0;
f(2) = 1;
sum=1;
% sum of the 50 Fibonacci numbers
for i = 3 : 50
% Perform the sum of terms accordingly
f(i) = f(i-1) + f(i-2);
sum=sum+f(i);
end
disp(sum)
