Plot results of ODES.
1 次查看(过去 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!