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

2 Ansichten (letzte 30 Tage)
Tyler
Tyler am 5 Feb. 2013
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

Antworten (1)

Walter Roberson
Walter Roberson am 5 Feb. 2013
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')

Kategorien

Mehr zu Graphics Performance finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by