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