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

82 lines
2.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
layout: default
---
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
<h1 id="function-solveode">Function solveODE <a href="#function-solveode" title="Permalink">#</a></h1>
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]`
<h2 id="syntax">Syntax <a href="#syntax" title="Permalink">#</a></h2>
```js
math.solveODE(func, tspan, y0)
math.solveODE(func, tspan, y0, options)
```
<h3 id="parameters">Parameters <a href="#parameters" title="Permalink">#</a></h3>
Parameter | Type | Description
--------- | ---- | -----------
`func` | function | The forcing function f(t,y)
`tspan` | Array &#124; Matrix | The time span
`y0` | number &#124; BigNumber &#124; Unit &#124; Array &#124; Matrix | The initial value
`options` | Object | Optional configuration options
<h3 id="returns">Returns <a href="#returns" title="Permalink">#</a></h3>
Type | Description
---- | -----------
Object | Return an object with t and y values as arrays
<h3 id="throws">Throws <a href="#throws" title="Permalink">#</a></h3>
Type | Description
---- | -----------
<h2 id="examples">Examples <a href="#examples" title="Permalink">#</a></h2>
```js
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 })
```
<h2 id="see-also">See also <a href="#see-also" title="Permalink">#</a></h2>
[derivative](derivative.html),
[simplifyCore](simplifyCore.html)