How to create a loop with Fibonacci sequence

4 次查看(过去 30 天)
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.

回答(1 个)

KL
KL 2015-6-16
n(1) = 1;
n(2) = 1;
k=3
while k <= 10
n(k) = n(k-1)+n(k-2);
k=k+1;
end
  3 个评论
John D'Errico
John D'Errico 2018-11-4
@Ata - What have you tried? If nothing, why not? Answers is not here to do your homework for you. Anyway, your question has little to do with the question that was originally asked.
Saugyan Chapain
Saugyan Chapain 2019-4-1
i tried this but it prints everything, i mean for k(1), k(2)....
so , i got 10 outputs
how to correct this

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by