I am trying to write a program that returns a Fibonacci series in a two-dimensional array. It has two input integers 6and 9. The Fibonacci series in the first row has the same series in its first column.I need help to get the remaining rows and col

조회 수: 1 (최근 30일)
function A = mat_fibo(M,N) A(1)=1; A(1)=1; for ii = 2:M for jj = 3:N A(jj) =A(jj-1)+A(jj-2); if ii<=M A(2,1)=1; A(2,1)=2; A(ii+1,jj)=A(ii+1,jj-2)+A(ii+1,jj-1); end end end
  댓글 수: 2
Paul Ezeani
Paul Ezeani 2020년 5월 4일
This is the answer I want to achieve: 1 1 2 3 5 8 13 21 34 1 2 3 5 8 13 21 34 55 2 3 5 8 13 21 34 55 89 3 5 8 13 21 34 5 89 144 5 8 13 21 34 55 89 144 233 8 13 21 34 55 89 144 233 377

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

채택된 답변

David Hill
David Hill 2020년 5월 4일
Not sure if this is what you are looking for, it was hard to understand your explanation.
function A = mat_fibo(M,N)
a(1)=1;
a(2)=1;
c=2;
while c<N
c=c+1;
a(c)=a(c-1)+a(c-2);
end
A=repmat(a,M,1);
  댓글 수: 6

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

추가 답변 (0개)

카테고리

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