Power matrix A^t using for loop without overwriting previous values

조회 수: 1 (최근 30일)
Hi, I am trying to compute the value of at and pt, where at is the minimum column sum and pt is the maximum column sum, from t=0 to 5. I wrote this code:
A=[0 0 0.319; 0.49 0 0; 0 0.87 0.87];
for t=0:5;
At=A^t;
Asum=sum(At);
at=min(Asum);
pt=max(Asum);
hold on
plot(t,at,t,pt);
end
The problem is the result that showed up is only the last value of t=5. I need to have the values of at and pt when t=0,1,2,3,4,5 and then plot it.
Any help would be greatly appreciated. Thank you!

채택된 답변

Mohammad Abouali
Mohammad Abouali 2015년 11월 24일
편집: Mohammad Abouali 2015년 11월 24일
A=[0 0 0.319; ...
0.49 0 0; ...
0 0.87 0.87];
at=nan(6,1);
pt=nan(6,1);
for t=0:5
At=A^t;
Asum=sum(At);
at(t+1)=min(Asum);
pt(t+1)=max(Asum);
end
plot(0:5,at,0:5,pt);
Also check if you really meant At=A^t; or did you mean At=A.^t! They are not the same thing.
  댓글 수: 3

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

추가 답변 (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