Power matrix A^t using for loop without overwriting previous values
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
jnovv
il 24 Nov 2015
Modificato: Mohammad Abouali
il 24 Nov 2015
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 Commenti
Risposta accettata
Mohammad Abouali
il 24 Nov 2015
Modificato: Mohammad Abouali
il 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 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!