Plot results of ODES.

조회 수: 1 (최근 30일)
Marios Christofides
Marios Christofides 2020년 7월 9일
댓글: James Tursa 2020년 7월 9일
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
Marios Christofides 2020년 7월 9일
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에서 Mathematics에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by