ODE Solver Running Very "Slowly"

2 views (last 30 days)
성주
성주 on 25 Oct 2023
Answered: Star Strider on 25 Oct 2023
"Hi, I'm attempting to numerically solve differential equations using ode45. I'm aiming to obtain results within the 0 to 100-second range. However, the computation is taking an excessively long time, and I haven't received any results yet. Are there any options I can employ to expedite the process?"
t= linspace(0,100,1000)
[t,y]= ode45(@f,t,[0.785398163 0]);
plot(t, y(:, 1))
function dydt = f(t,y)
dydt = [(2.17147)*y(2); -3.14352E+14*(y(2)) - 9.97162E+15*sin(2*y(1))];
end

Answers (1)

Star Strider
Star Strider on 25 Oct 2023
Your system is ‘stiff’ because the parameters span several orders-of-magnitude. Use a ‘stiff’ solver such as ode15s instead —
t= linspace(0,100,1000);
tic
[t,y]= ode15s(@f,t,[0.785398163 0]);
toc
Elapsed time is 0.106661 seconds.
figure
plot(t, y(:, 1))
figure
plot(t, y(:, 1))
xlim([0 1])
function dydt = f(t,y)
dydt = [(2.17147)*y(2); -3.14352E+14*(y(2)) - 9.97162E+15*sin(2*y(1))];
end
.

Tags

Community Treasure Hunt

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

Start Hunting!