scijs/ode-rk4

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

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

ode-rk4 Build Status npm version Dependency Status

Integrate a system of ODEs using the Fourth Order Runge-Kutta (RK-4) method

Introduction

This module integrates a system of ordinary differential equations of the form

\begin{eqnarray*} y'(t) &=& f(t, y(t)), \\ y(t_0) &=& y_0 \end{eqnarray*}

where y is a vector of length n. Given time step \Delta t, the Runge-Kutta 4 method integrates the ODE with update

\begin{eqnarray*} y_{n+1} &=& \frac{\Delta t}{6}\left(k_1 + 2k_2 + 2k_3 + k_4\right) \\ t_{n+1} &=& t_n + \Delta t \end{eqnarray*}

where k_n are given by

\begin{eqnarray*} k_1 &=& f(t_n, y_n), \\ k_2 &=& f(t_n + \frac{\Delta t}{2}, y_n + \frac{\Delta t}{2} k_1), \\ k_3 &=& f(t_n + \frac{\Delta t}{2}, y_n + \frac{\Delta t}{2} k_2), \\ k_4 &=& f(t_n + \Delta t, y_n + \Delta tk_3).  \end{eqnarray*}

For a similar adaptive method using the fifth order Cash-Karp Runge-Kutta method with fourth order embedded error estimator, see ode45-cash-karp.

Install
m install ode-rk4
Example
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 ]
API
require('ode-rk4')( y0, deriv, t0, dt )

Arguments:

Returns: Initialized integrator object.

Properties:

Methods:

Credits

(c) 2015 Ricky Reusser. MIT License


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.