Documentation / @interstellar-tools/equations / rk4Step
Function: rk4Step()
ts
function rk4Step(
f: OdeRightHandSideType,
t: number,
y: readonly number[],
h: number
): number[];Defined in: helpers/rk4.ts:42
Take one fourth-order Runge–Kutta step of a system of ODEs,
with
Notes
- The error per step shrinks as
, and over a fixed interval as : halving the step makes the result about 16 times more accurate. - A fixed step suits smooth problems. Close passes, where the forces change quickly, need a step small enough for the closest one.
hmay be negative, to integrate backwards.
Parameters
| Parameter | Type | Description |
|---|---|---|
f | OdeRightHandSideType | The right-hand side y. |
t | number | Time |
y | readonly number[] | State t (finite components). |
h | number | Step size |
Returns
number[]
The state at t + h.
Throws
- If
t,hor a component ofyis not finite, orfreturns an array of the wrong length. - If
his zero.
Example
ts
// dy/dt = y from y = 1: one step of 0.1 gives e^0.1 to 7 digits
rk4Step((_t, [y]) => [y], 0, [1], 0.1); // [1.1051708...]See
- rk4Integrate
- https://en.wikipedia.org/wiki/Runge–Kutta_methods Runge–Kutta methods