Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including ode-midpoint with all npm packages installed. Try it out:

var odeMidpoint = require("ode-midpoint")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

ode-midpoint v1.0.6

Integrate a system of ODEs using the Second Order Runge-Kutta (Midpoint) method

ode-midpoint Build Status npm version Dependency Status

Integrate a system of ODEs using the Second Order Runge-Kutta (Midpoint) method


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



where undefined is a vector of length undefined. Given time step undefined, the midpoint method integrates the ODE with update



$ npm install ode-midpoint


var midpoint = require('ode-midpoint')

var deriv = function(dydt, y, t) {
  dydt[0] = -y[1]
  dydt[1] =  y[0]

var y0 = [1,0]
var n = 1000
var t0 = 0
var dt = 2.0 * Math.PI / n

var integrator = midpoint( y0, deriv, t0, dt )

// Integrate 1000 steps:

// Integrate all the way around a circle:
// => integrator.y = [ 1.0000001939636542, 0.000041341220643982546 ]


require('ode-midpoint')( y0, deriv, t0, dt )


  • 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 calcualted derivative dydt.
  • t0: initial time undefined.
  • dt: time step undefined.

Returns: Initialized integrator object.


  • n: dimension of y0.
  • y: current state. Initialized as a shallow copy of input y0.
  • deriv: function that calcualtes derivative. Initialized from input. May be changed.
  • t: current time, incremented by dt with each time step.
  • dt: time step undefined. Initialized from input dt. May be changed.


  • .step(): takes a single step of the midpoint integrator and stores the result in-place in the y property.
  • .steps( n ): takes n steps of the midpoint integrator, storing the result in-place in the y property.


(c) 2015 Ricky Reusser. MIT License


RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free