Plot results of ODES.

1 vue (au cours des 30 derniers jours)
Marios Christofides
Marios Christofides le 9 Juil 2020
Commenté : James Tursa le 9 Juil 2020
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 commentaires
Marios Christofides
Marios Christofides le 9 Juil 2020
I didn't use ODE45 and I don't know how to do it using a for loop.
James Tursa
James Tursa le 9 Juil 2020
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.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Mathematics dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by