Solving as ODE45 and ODE15s gives different results

조회 수: 8 (최근 30일)
Marco Sammito
Marco Sammito 2016년 11월 10일
답변: Marco Sammito 2016년 11월 10일
Hi, I have to solve this problem
as it were a DAE (I know I could just substitute h into the equation, but this is just an example, because in reality the problem I have to solve is a DAE and more complex than this). When I use ode45 and treat the problem as a second order differential equation, the graph t Vs y is
but when I treat it as a DAE, the graph is completely different
and I do not understand why. Here is my code:
ode45 second order differential equation
function yp = dae_normale(t,y)
yp = zeros(2,1);
yp(1) = y(2);
yp(2) = 4*y(2) + 1/(5*y(2) - 2*y(1) ) - 7*y(1);
ode45 second order differential equation run
[t,y] = ode45('dae_normale',[1,5],[1,1]);
[t,y(:,1)]
plot(t,y(:,1))
DAE ode15s
function out = dae(t,y)
out = [y(2)
4*y(2) + 1/y(3) - 7*y(1)
y(3) - 5*y(2) + 2*y(1) ];
DAE ode15s run
y0 = [1; 1; 3];
M = [1 0 0; 0 1 0; 0 0 0];
options = odeset('Mass',M);
[t,y] = ode15s(@dae,[1 5],y0,options);
[t,y(:,1)]
plot(t,y(:,1))
Thank you.
  댓글 수: 3
Marco Sammito
Marco Sammito 2016년 11월 10일
I edited the original message.
Torsten
Torsten 2016년 11월 10일
Maybe you should try what happens when you strengthen the tolerances for ODE45 in the options structure (RelTol=1e-8, AbsTol=1e-8).
Best wishes
Torsten.

댓글을 달려면 로그인하십시오.

답변 (1개)

Marco Sammito
Marco Sammito 2016년 11월 10일
I tried following Torsten's suggestion and now the two graphs are almost equal. Here is the code I modified as Torsten pointed out:
ode45 second order differential equation run
options = odeset('RelTol',1e-8,'AbsTol',[1e-8 1e-8]);
[t,y]=ode45('dae_normale',[1,5],[1,1],options);
[t,y(:,1)]
plot(t,y(:,1))

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by