Main Content

ODE 选项摘要

解算 ODE 经常要求微调参数、调整误差容限或向求解器传递附加信息。本主题说明如何为求解器函数(ode45ode15s 等)指定选项以及每个选项与哪些微分方程求解器兼容。

选项语法

使用 odeset 函数创建 options 结构体,然后将其作为第四个输入参量传递给求解器。例如,要调整相对和绝对误差容限,请使用以下命令:

opts = odeset(RelTol=1e-2,AbsTol=1e-5);
[t,y] = ode45(@odefun,tspan,y0,opts);

如果您使用不带输入参数的 odeset 命令,MATLAB® 将显示每个选项的可能值列表,并以花括号 {} 表示默认值。

odeget 函数可以查询现有结构体中的选项值,您可以用该函数来根据条件动态更改选项值。例如,以下代码检测 Stats 是否设置为 "on",并根据需要更改其值:

if isempty(odeget(opts,"Stats"))
  odeset(opts,Stats="on")
end

选项与每个求解器的兼容性

odeset 中,有些选项是通用的,可与任何求解器兼容,还有一些选项是特定于求解器的。下表总结了每个选项与不同求解器之间的兼容性。

选项组选项ode45ode23ode78ode89ode113ode15sode23sode23tode23tbode15i
误差控制RelTol

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

AbsTol

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

NormControl

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

求解器输出NonNegative

Supported

Supported

Supported

Supported

Supported

Supported

Unsupported

Supported

Supported

Unsupported

OutputFcn

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

OutputSel

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Refine

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Stats

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

步长InitialStep

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

MaxStep

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

MinStep

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

事件位置Events

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

雅可比矩阵Jacobian

Unsupported

Unsupported

Unsupported

Unsupported

Unsupported

Supported

Supported

Supported

Supported

Supported

JPattern

Unsupported

Unsupported

Unsupported

Unsupported

Unsupported

Supported

Supported

Supported

Supported

Supported

Vectorized

Unsupported

Unsupported

Unsupported

Unsupported

Unsupported

Supported

Supported

Supported

Supported

Supported

质量矩阵和 DAEMass

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Supported

Unsupported

MStateDependence

Supported

Supported

Supported

Supported

Supported

Supported

Unsupported

Supported

Supported

Unsupported

MvPattern

Unsupported

Unsupported

Unsupported

Unsupported

Unsupported

Supported

Unsupported

Supported

Supported

Unsupported

MassSingular

Unsupported

Unsupported

Unsupported

Unsupported

Unsupported

Supported

Unsupported

Supported

Unsupported

Unsupported

InitialSlope

Unsupported

Unsupported

Unsupported

Unsupported

Unsupported

Supported

Unsupported

Supported

Unsupported

Unsupported

ode15sode15i 的算法选项MaxOrder

Unsupported

Unsupported

Unsupported

Unsupported

Unsupported

Supported

Unsupported

Unsupported

Unsupported

Supported

BDF

Unsupported

Unsupported

Unsupported

Unsupported

Unsupported

Supported

Unsupported

Unsupported

Unsupported

Unsupported

* 只有在解算不涉及质量矩阵的问题时,才对 ode15sode23tode23tb 求解器使用 NonNegative 参数。

** ode15i 的事件函数必须接受 yp 的第三个输入参量。

用法示例

MATLAB 包含几个示例文件,说明了如何使用各种选项。例如,键入 edit ballode 查看使用 'Events' 指定事件函数的示例,或键入 edit batonode 查看使用 'Mass' 指定质量矩阵的示例。有关示例文件及其使用的选项的完整总结,请参阅 ODE 示例和文件摘要

另请参阅

|

相关主题