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 个评论
Walter Roberson
2020-3-23
I suspect that you need a stiff solver such as ode23s
回答(2 个)
Walter Roberson
2020-3-25
1 个投票
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
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))

类别
在 帮助中心 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!