Name: ode-rk4
Owner: scijs
Description: Integrate a system of ODEs using the Fourth Order Runge-Kutta (RK-4) method
Created: 2015-07-24 16:13:52.0
Updated: 2018-05-22 20:49:01.0
Pushed: 2015-08-10 02:47:02.0
Homepage: null
Size: 272
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Integrate a system of ODEs using the Fourth Order Runge-Kutta (RK-4) method
This module integrates a system of ordinary differential equations of the form
where is a vector of length . Given time step , the Runge-Kutta 4 method integrates the ODE with update
where are given by
For a similar adaptive method using the fifth order Cash-Karp Runge-Kutta method with fourth order embedded error estimator, see ode45-cash-karp.
m install ode-rk4
rk4 = require('ode-rk4')
deriv = function(dydt, y, t) {
dt[0] = -y[1]
dt[1] = y[0]
y0 = [1,0]
n = 1000
t0 = 0
dt = 2.0 * Math.PI / n
integrator = rk4( y0, deriv, t0, dt )
ntegrate 1000 steps:
grator.steps(n)
ntegrate all the way around a circle:
> integrator.y = [ 0.9999999999995743, -8.160481752145232e-11 ]
require('ode-rk4')( y0, deriv, t0, dt )
Arguments:
y0
: an array or typed array containing initial conditions. This vector is updated in-place with each integrator step.deriv
: a function that calculates the derivative. Format is function( dydt, y, t )
. Inputs are current state y
and current time t
, output is the calculated derivative dydt
.t0
: initial time .dt
: time step .Returns: Initialized integrator object.
Properties:
n
: dimension of y0
.y
: current state. Initialized as a shallow copy of input y0
.deriv
: function that calculates the derivative. Initialized from input. May be changed.t
: current time, incremented by dt
with each time step.dt
: time step . Initialized from input dt
. May be changed.Methods:
.step()
: takes a single step of the RK-4 integrator and stores the result in-place in the y
property..steps( n )
: takes n
steps of the RK-4 integrator, storing the result in-place in the y
property.(c) 2015 Ricky Reusser. MIT License