Why ode45 is not working?

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 comentario

Walter Roberson
Walter Roberson el 23 de Mzo. de 2020
I suspect that you need a stiff solver such as ode23s

Iniciar sesión para comentar.

Respuestas (2)

Walter Roberson
Walter Roberson el 25 de Mzo. de 2020

1 voto

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 el 23 de Mzo. de 2020

0 votos

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))

Etiquetas

Preguntada:

el 23 de Mzo. de 2020

Respondida:

el 25 de Mzo. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by