Function solveODE #
常微分方程数值积分
提供两种可变步长方法
- “RK23”:Bogacki–Shampine 方法
- “RK45”:Dormand-Prince 方法 RK5(4)7M (默认)
参数预期如下。
func应该是驱动函数f(t, y)tspan应该是一个包含两个数字或单位的向量[tStart, tEnd]y0初始状态值,应为标量或扁平数组options应该是一个包含以下信息的对象method(‘RK45’):[‘RK23’, ‘RK45’]tol(1e-3):方法的数值容差,求解器将误差估计保持在此值以下firstStep:初始步长minStep:方法的最小步长maxStep:方法的最大步长minDelta(0.2):步长变化的最小比率maxDelta(5):步长变化的最大比率maxIter(1e4):最大迭代次数
返回值是一个包含 {t, y} 的对象,请注意,尽管 t 表示时间,但它可以代表任何其他独立变量,例如 x
t一个大小为[n]的数组y状态数组可能以两种方式返回- 如果
y0是标量: 返回一个大小为[n]的类数组 - 如果
y0是大小为 [m] 的扁平类数组: 返回一个大小为[n, m]的类数组
- 如果
Syntax #
math.solveODE(func, tspan, y0)
math.solveODE(func, tspan, y0, options)
Parameters #
| Parameter | Type | Description |
|---|---|---|
func |
function | 驱动函数 f(t,y) |
tspan |
Array | Matrix | 时间跨度 |
y0 |
number | BigNumber | Unit | Array | Matrix | 初始值 |
options |
Object | 可选配置选项 |
Returns #
| Type | Description |
|---|---|
| Object | 返回一个包含 t 和 y 值的数组的对象 |
Throws #
Type | Description —- | ———–
Examples #
function func(t, y) {return y}
const tspan = [0, 4]
const y0 = 1
math.solveODE(func, tspan, y0)
math.solveODE(func, tspan, [1, 2])
math.solveODE(func, tspan, y0, { method:"RK23", maxStep:0.1 })