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

1 回表示 (過去 30 日間)
jnovv
jnovv 2015 年 11 月 24 日
編集済み: Mohammad Abouali 2015 年 11 月 24 日
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 件のコメント
jnovv
jnovv 2015 年 11 月 24 日
And yes it is A^t.
Mohammad Abouali
Mohammad Abouali 2015 年 11 月 24 日
You are welcome

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by