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
Showing posts with label for. Show all posts
Showing posts with label for. Show all posts
Wednesday, August 25, 2010
Saturday, August 14, 2010
HOW TO USE 'FOR'LOOP
SYNTAX:
for counter=legal list of values
statement to be executed repeatedly with in this loop
end
Example:
>> sum=0;
>> for i=1:10
sum=sum+i;
end
>> sum
sum =
55
for counter=legal list of values
statement to be executed repeatedly with in this loop
end
Example:
>> sum=0;
>> for i=1:10
sum=sum+i;
end
>> sum
sum =
55
Subscribe to:
Posts (Atom)