Plot results of ODES.

1 次查看(过去 30 天)
Marios Christofides
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 个评论
Marios Christofides
I didn't use ODE45 and I don't know how to do it using a for loop.
James Tursa
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 个)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by