Why ode45 is not working?

조회 수: 8 (최근 30일)
Joana Costa
Joana Costa 2020년 3월 23일
답변: Walter Roberson 2020년 3월 25일
Hello, I am trying to solve the following equations using ode45:
function dydt = odefun3(t,y)
dydt = zeros(3,1);
dydt(1) = 4.86*y(3) - 4.86*10^14*y(1)*y(2);
dydt(2) = 4.86*y(3) - 4.86*10^14*y(1)*y(2);
dydt(3) = -4.86*y(3) + 4.86*10^14*y(1)*y(2);
tspan = [0 0.05 0.5 1 4];
y0 = [1.48*10^-8; 6.7608*10^-3; 1];
[t,y] = ode45(@(t,y) odefun3(t,y),tspan,y0);
I am having problems because I am not getting results, it takes too long. I am thinking it can be a time step problem because if I use a smaller tspan = [0 1*10^-10] I can get results however I will need results accordingly to tspan = [0 0.05 0.5 1 4].
Have you got any idea about this? Thank you for your help.
  댓글 수: 1
Walter Roberson
Walter Roberson 2020년 3월 23일
I suspect that you need a stiff solver such as ode23s

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

답변 (2개)

Walter Roberson
Walter Roberson 2020년 3월 25일
Your function wiggles a lot, with the first derivative crossing and recrossing 0. ode45s needs to take very small steps in order to model the behaviour properly.
If you change from ode45 to ode23s then it will finish quickly, at the expensive of not being completely accurate at the fine detail.

darova
darova 2020년 3월 23일
I changed tspan
f = @(t,y) [ 4.86*y(3) - 4.86*10^14*y(1)*y(2);
4.86*y(3) - 4.86*10^14*y(1)*y(2);
-4.86*y(3) + 4.86*10^14*y(1)*y(2) ];
opt = odeset('maxstep',1e-13);
tspan = [0 1e-11];
y0 = [1.48e-8; 6.7608e-3; 1];
[t,y] = ode45(f,tspan,y0,opt);
subplot(311)
plot(t,y(:,1))
subplot(312)
plot(t,y(:,2))
subplot(313)
plot(t,y(:,3))

카테고리

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