FIBONNACI SERIES:
Let us use matlab to compute the FIBONNACI SERIES 1, 1, 2, 3, 5, 8, 13, 21,.........
We know the first two elements starts with 1,1 & each next element is sum of the two previous elements.
We are going to use FOR loop for finding the fibonnaci series.
SYNTAX for ‘FOR’ LOOP:
for counter=legal list of values
......statement to be executed repeatedly with in this loop
end
MATLAB CODING FOR FINDING FIBONNACI SERIES:
f(1)=1;
f(2)=1;
for i=3:11
f(i)=f(i-1)+f(i-2);
end
f(1:11)
ans =
1 1 2 3 5 8 13 21 34 55 89
No comments:
Post a Comment