2023-07-19 14:18:03 +02:00

2.7 KiB
Raw Blame History

layout
default

Function solveODE #

Numerical Integration of Ordinary Differential Equations

Two variable step methods are provided:

  • "RK23": BogackiShampine method
  • "RK45": Dormand-Prince method RK5(4)7M (default)

The arguments are expected as follows.

  • func should be the forcing function f(t, y)
  • tspan should be a vector of two numbers or units [tStart, tEnd]
  • y0 the initial state values, should be a scalar or a flat array
  • options should be an object with the following information:
    • method ('RK45'): ['RK23', 'RK45']
    • tol (1e-3): Numeric tolerance of the method, the solver keeps the error estimates less than this value
    • firstStep: Initial step size
    • minStep: minimum step size of the method
    • maxStep: maximum step size of the method
    • minDelta (0.2): minimum ratio of change for the step
    • maxDelta (5): maximum ratio of change for the step
    • maxIter (1e4): maximum number of iterations

The returned value is an object with {t, y} please note that even though t means time, it can represent any other independant variable like x:

  • t an array of size [n]
  • y the states array can be in two ways
    • if y0 is a scalar: returns an array-like of size [n]
    • if y0 is a flat array-like of size [m]: returns an array like of size [n, m]

Syntax #

math.solveODE(func, tspan, y0)
math.solveODE(func, tspan, y0, options)

Parameters #

Parameter Type Description
func function The forcing function f(t,y)
tspan Array | Matrix The time span
y0 number | BigNumber | Unit | Array | Matrix The initial value
options Object Optional configuration options

Returns #

Type Description
Object Return an object with t and y values as arrays

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 })

See also #

derivative, simplifyCore