Why ode45 is not working?
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
Antworten (2)
Walter Roberson
am 25 Mär. 2020
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.
0 Kommentare
darova
am 23 Mär. 2020
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))

0 Kommentare
Siehe auch
Kategorien
Mehr zu Ordinary Differential Equations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!