# Fibonacci sequence in MATLAB

The Fibonacci sequence is a set of numbers that start with a one or a zero, followed by a one, and proceeds based on the rule that each number is equal to the sum of the preceding two numbers.

Example :- 0 , 1 , 1 , 2 , 3 , 5 , 8 ,13 , 21 …..

We can generate a series of Fibonacci numbers using MATLAB.

The algorithm for it is very simple.

1. We initialize two variables as 0 and 1. This is because a series always starts with 0 and a 1.
2. After this, we take an input from user where the user has to enter the no. of terms he wants in the series.
3. Accordingly, a for loop is executed where it prints all the terms of the sequence that the user wants and exits the loop.

Following is the Matlab code for the Fibonacci sequence.

MATLAB CODE

```a=0;
b=1;
n=input('Enter no. of terms : ');
for i=1:n
fprintf('%d',a) ;
fprintf('\t');
c=a+b;
a=b;
b=c;
end
fprintf('\n')
```

`OUTPUT`

When I enter number of terms:- 2

When I enter number of terms:- 3

When I enter number of terms:- 6

##### SAURAB S

I am currently pursuing my btech in Electronics and communication engineering from Amrita Vishwa Vidyapeetham. My areas of interest are signal processing, Communication systems, Control system.

### Recommended Posts

##### Test Post

17 Feb 2018 - Tutorial

##### Counters using conditionally executed subsystems | Simulink Tutorial

16 Feb 2018 - Simulink, Tutorial

##### Regulating drum boiler pressure

16 Feb 2018 - Simulink, Tutorial