Skip to content

A swift implementation of explict runge-kutta ODE integration using the Dormond Price RK5(4) method

Notifications You must be signed in to change notification settings

martinjrobins/swift-odeint

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OdeInt

Swift

A swift implementation of explict runge-kutta ODE integration using the Dormond Price RK5(4) method, also known as the DOPRI method. This uses adaptive time-stepping, and dense output to the times specified by the user.

The original method is documented in [1] as method 7M, and the dense output is documented in [2], Section 4.

Usage

The protocol OdeVector defines a state vector to be used in the integration, and both the standard SIMD types as well as the Double and Float types have been extended to conform to this protocol. Thus you can solve the ODE given by $dy/dx = -y$ with initial condition $y(0) = 1.0$ with the following:

let times = Array<Double>(stride(from: 0.0, through: 1.0, by: 0.001))
let results = Double.integrate(over: times, y0: 1.0, tol: 1e-6) { y, t in
  return -y
}

Or you can solve the same ODE using a vector initial condition $y(0) = [1, 2]$ using:

let times = Array<Float>(stride(from: 0.0, through: 1.0, by: 0.001))
let results = SIMD2<Float>.integrate(over: times, y0: [1.0, 2.0], tol: 1e-6) { y, t in
  return -y
}

References

[1] Dormand, J. R., & Prince, P. J. (1980). A family of embedded Runge-Kutta formulae. Journal of computational and applied mathematics, 6(1), 19-26.

[2] Dormand, J. R., & Prince, P. J. (1986). Runge-Kutta triples. Computers & Mathematics with Applications, 12(9), 1007-1017.

About

A swift implementation of explict runge-kutta ODE integration using the Dormond Price RK5(4) method

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages