Images, snippets, snapshots, math

View Gabriele Lami's profile on LinkedIn

martedì 29 dicembre 2009

Verlet integration in Haskell

Verlet integration algorithm written in 3 minutes


-- Verlet integration

projOneTwo ( a, b, c , d ,e ) = ( a, b)

nextStepInt (_ ,_ , 0 ,_ ,_ ) = []
nextStepInt ( xt ,vt , n , acc , h ) =
let
atph = acc . ( xt + ) $ h
vtph = vt + atph * h * 0.5
xtph = xt + h * vt + 0.5 * acc xt * h^2
in
( xtph, vtph , n-1 , acc , h ) : nextStepInt ( xtph, vtph , n-1 , acc , h )
timeInt ( xt ,vt , n , acc , h ) = map ( projOneTwo ) $ nextStepInt ( xt ,vt , n , acc , h )


example ( spring ) :
timeInt (0 , 1 , 10000 , (\x -> 0.1 * ( - x ) ) , 0.2 )

2 commenti:

Anonimo ha detto...

Nice post and this fill someone in on helped me alot in my college assignement. Say thank you you on your information.

Anonimo ha detto...

hello


Just saying hello while I read through the posts


hopefully this is just what im looking for looks like i have a lot to read.