ode15s 求解器是适用于大多数刚性问题的首选求解器。但是,对于特定类型的问题,其他刚性求解器可能更高效。本示例使用所有四个刚性 ODE 求解器解算刚性测试方程。
请考虑以下测试方程:
y′=-λy.
随着 λ 的量级增加,方程的刚性逐渐增强。使用 λ=1×109、初始条件 y(0)=1 和时间区间 [0 0.5]。这些值使该问题足够刚性,从而使 ode45 和 ode23 需要对该方程进行积分。此外,还使用 odeset 传入常量 Jacobian J=∂f∂y=-λ 并打开求解器统计信息的显示。
lambda = 1e9;
y0 = 1;
tspan = [0 0.5];
opts = odeset('Jacobian',-lambda,'Stats','on');
使用 ode15s、ode23s、ode23t 和 ode23tb 对方程求解。生成子图进行比较。
subplot(2,2,1)
tic, ode15s(@(t,y) -lambda*y, tspan, y0, opts), toc
104 successful steps
1 failed attempts
212 function evaluations
0 partial derivatives
21 LU decompositions
210 solutions of linear systems
Elapsed time is 2.504340 seconds.
title('ode15s')
subplot(2,2,2)
tic, ode2