ode-euler
Integrate a system of ODEs using the Euler method
Introduction
This module integrates a system of ordinary differential equations of the form
where is a vector of length . Given time step , the Euler method integrates the ODE with updateInstall
$ npm install ode-euler
Example
var euler = var { dydt0 = -y1 dydt1 = y0} var y0 = 10var n = 1000var t0 = 0var dt = 20 * MathPI / n var integrator = // Integrate 1000 steps:integrator // Integrate all the way around a circle:// => integrator.y = [ 1.0199349143076457, -0.00008432969374211775 ]
API
require('ode-euler')( 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 isfunction( dydt, y, t )
. Inputs are current statey
and current timet
, output is calcualted derivativedydt
.t0
: initial time .dt
: time step .
Returns: Initialized integrator object.
Properties:
n
: dimension ofy0
.y
: current state. Initialized as a shallow copy of inputy0
.deriv
: function that calcualtes derivative. Initialized from input. May be changed.t
: current time, incremented bydt
with each time step.dt
: time step . Initialized from inputdt
. May be changed.
Methods:
.step()
: takes a single step of the Euler integrator and stores the result in-place in they
property..steps( n )
: takesn
steps of the Euler integrator, storing the result in-place in they
property.
Credits
(c) 2015 Ricky Reusser. MIT License