Power matrix A^t using for loop without overwriting previous values
2 views (last 30 days)
Show older comments
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!
0 Comments
Accepted Answer
Mohammad Abouali
on 24 Nov 2015
Edited: Mohammad Abouali
on 24 Nov 2015
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 Comments
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!