How to store and then plot values in a for loop?

My goal: plot T1, T2, and T3 on a graph when the matrix is solved at each value of "i" from 0 to 50 for d. What my code currently does is solve a system at various values of "i" for three variables. the end result (aka the values I am trying to store) end up being T1, T2, and T3. The problem is, it only uses the last value of each of those, and not the entire spectrum of results. How can i store each result for those three values and plot them on a graph to show how they relate over time?
for d=0:.1:50;
i=d*-40000;
B=[-40000; i; 0];
A=[1 1 1; 10 28 40; 144 -240 180];
T=[(A^(-1)*B)];
T1=T(1);
T2=T(2);
T3=T(3);
end

回答 (1 件)

Walter Roberson
Walter Roberson 2013 年 2 月 5 日

0 投票

A = [1 1 1; 10 28 40; 144 -240 180];
dvals = 0:.1:50;
for K = 1 : length(dvals)
d = dvals(K);
i = d * -40000;
B = [-40000; i; 0];
T = A \ B;
T1(K) = T(1);
T2(K) = T(2);
T3(K) = T(3);
end
plot( dvals, T1, '^', dvals, T2, 's', dvals, T3, 'p')

カテゴリ

ヘルプ センター および File ExchangeGraphics Performance についてさらに検索

質問済み:

2013 年 2 月 5 日

Community Treasure Hunt

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

Start Hunting!

Translated by