Plot results of ODES.
2 ビュー (過去 30 日間)
古いコメントを表示
I'm trying to model a PI and wanted to graph the results of the for loop that is solving the four ODEs. I'm not sure how to graph the results. Can anybody help?
hi1 = 0;
hi2 = 0;
hi3 = 5;
ys = 10;
u = 1;
Kc = 7.84;
ti = 4.424;
zi4 = 0;
f = 'Time'; g = 'h1'; h = 'h2'; p = 'h3'; r = 'u';
fprintf('Time \t h1\t h2\t \t h3 \t \t u\n', f, g, h, p, u)
t = 0;
fprintf('%5.2f \t %5.2f \t %5.2f \t %5.2f \t %5.2f\n',t,hi1,hi2,hi3,u );
for i = 1:2:10
%Forward Euler Method
u = Kc * (ys - hi3) + (Kc/ti)*zi4;
h1 = (1/10)*dt*(u - (hi1));
h2 = (1/2)*dt*(hi1-hi2);
h3 = dt*((hi2-hi3));
z4 = ys - hi3
hi1 = h1;
hi2 = h2;
hi3 = h3;
zi4 = z4;
fprintf('%5.2f \t %5.2f \t %5.2f \t %5.2f\n',t,h1,h2,h3,u);
end
2 件のコメント
James Tursa
2020 年 7 月 9 日
Store your intermediate results (the values in the loop) in arrays. Then after the loop you can plot them.
Can you post the four differential equations you are solving? Your Euler method looks a bit strange and I would like to check your code against the equations.
回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!