Thursday, 10 January 2013

MATLAB Fibonacci Code

Read these books to get the knowledge on MATLAB more better.

 MatLab Fibonacci Sequence :

Code :

n = input('n (number of Fibonacci numbers to compute): ');
f(1) = 1; f(2) = 1;
for i = 3:n
f(i) = f(i-1) + f(i-2)
end

Input :
n (number of Fibonacci numbers to compute): 7

Output :

f = 
1 1 2
f = 
1 1 2 3
f =
1 1 2 3 5
f =
1 1 2 3 5 8
f =
1 1 2 3 5 8 13

Here is also the code for the fibonacci series in C++ :
http://gappcode.blogspot.in/2013/11/c-fibonacci-series.html

Read these books to get the knowledge on MATLAB more better.

1 comment:

  1. Not to be persnickety, but I would add standard


    %Clear screen and memory

    clear; clc;


    at the start of the script, especially for beginners who ar unfamiliar with Matlab standard procedures.

    ReplyDelete