How to create a loop with Fibonacci sequence

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일

0 개 추천

n(1) = 1;
n(2) = 1;
k=3
while k <= 10
n(k) = n(k-1)+n(k-2);
k=k+1;
end

댓글 수: 3

Ata Ataser
Ata Ataser 2018년 11월 4일
how could i write a program that checks if the input is a fibonacci number or not and prints it ?
@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.
i tried this but it prints everything, i mean for k(1), k(2)....
so , i got 10 outputs
how to correct this

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

2015년 6월 16일

댓글:

2019년 4월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by