MATLAB Answers

How to create a loop with Fibonacci sequence

29 views (last 30 days)
Petra Hausfeld
Petra Hausfeld on 16 Jun 2015
Commented: Saugyan Chapain on 1 Apr 2019
n(k) = n(k -1) + n(k- 2) with n(1) = n(2) = 1
Calculate next 10 elements and start with vector [1 1] where at each run one element should be added. I always get a mistake.

Answers (1)

KL
KL on 16 Jun 2015
n(1) = 1;
n(2) = 1;
k=3
while k <= 10
n(k) = n(k-1)+n(k-2);
k=k+1;
end
  3 Comments
Saugyan Chapain
Saugyan Chapain on 1 Apr 2019
i tried this but it prints everything, i mean for k(1), k(2)....
so , i got 10 outputs
how to correct this

Sign in to comment.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!