[Haskell-cafe] representing differencial equations in haskell
lemming at henning-thielemann.de
Tue Sep 25 09:20:50 EDT 2007
On Tue, 25 Sep 2007, Thomas Girod wrote:
> Let's say I have mathematical model composed of several differential
> equations, such as :
> di/dt = cos(i)
> dc/dt = alpha * (i(t) - c(t))
> (sorry my maths are really bad, but I hope you get the point)
> I would like to approximate the evolution of such a system iteratively. How
> would you do that in haskell ?
Solving differential equations in Haskell can be done in a very elegant
manner. My favorite example:
integrate :: Num a => a -> [a] -> [a]
integrate = scanl (+)
eulerExplicit :: Num a => (a -> a -> a) -> a -> a -> [a]
eulerExplicit f x0 y0 =
let x = iterate (1+) x0
y = integrate y0 y'
y' = zipWith f x y
It's left as an exercise to extend this to two differential equations.
Jerzy Karczmarczuk: "Lazy Processing and Optimization of Discrete Sequences"
More information about the Haskell-Cafe