# 求解非刚性 ODE

• ode45

• ode23

• ode78

• ode89

• ode113

### 示例：非刚性 van der Pol 方程

van der Pol 方程为二阶 ODE

ODE 方程组必须编码为 ODE 求解器能够使用的函数文件。ODE 函数的一般函数签名为

 dydt = odefun(t,y)

function dydt = vdp1(t,y) %VDP1 Evaluate the van der Pol ODEs for mu = 1 % % See also ODE113, ODE23, ODE45. % Jacek Kierzenka and Lawrence F. Shampine % Copyright 1984-2014 The MathWorks, Inc. dydt = [y(2); (1-y(1)^2)*y(2)-y(1)]; 

[t,y] = ode45(@vdp1,[0 20],[2; 0]); 

plot(t,y(:,1),'-o',t,y(:,2),'-o') title('Solution of van der Pol Equation (\mu = 1) using ODE45'); xlabel('Time t'); ylabel('Solution y'); legend('y_1','y_2') 

vdpode 函数可求解同一问题，但它接受的是用户指定的 值。随着 的增大，van der Pol 方程组将变成刚性。例如，对于值 ，您需要使用 ode15s 等刚性求解器来求解该方程组。

### 示例：非刚性欧拉方程

rigidode 在调用 ode45 时未使用任何输出参数，因此求解器会在每一步之后使用默认的输出函数 odeplot 自动绘制解点。

function rigidode %RIGIDODE Euler equations of a rigid body without external forces. % A standard test problem for non-stiff solvers proposed by Krogh. The % analytical solutions are Jacobian elliptic functions, accessible in % MATLAB. The interval here is about 1.5 periods; it is that for which % solutions are plotted on p. 243 of Shampine and Gordon. % % L. F. Shampine and M. K. Gordon, Computer Solution of Ordinary % Differential Equations, W.H. Freeman & Co., 1975. % % See also ODE45, ODE23, ODE113, FUNCTION_HANDLE. % Mark W. Reichelt and Lawrence F. Shampine, 3-23-94, 4-19-94 % Copyright 1984-2014 The MathWorks, Inc. tspan = [0 12]; y0 = [0; 1; 1]; % solve the problem using ODE45 figure; ode45(@f,tspan,y0); % -------------------------------------------------------------------------- function dydt = f(t,y) dydt = [ y(2)*y(3) -y(1)*y(3) -0.51*y(1)*y(2) ]; 

rigidode title('Solution of Rigid Body w/o External Forces using ODE45') legend('y_1','y_2','y_3','Location','Best')