Hello, I'm trying to write some simulator of physical systems using Yampa. The fundamental idea is to integrate the position and velocity, using the following algorithm:
1. get the velocity using the formula, v = v0 + integral ( 0.5 * force * recip mass) where v0 is the previous velocity. 2. calculate the new position as follows, x = x0 + integral (v) and some other steps that are not relevant here. Therefore I wrote the following piece of code: type Pos = Double type Vel = Double type Mass = Double type Force = Double integralCoordSF :: Force -> Mass -> SF (Pos,Vel) (Pos,Vel) integralCoordSF force mass = proc (x0,v0) -> do v <- integralVelSF force mass -< v0 vdt2 <- integral -< v let x = x0 + vdt2 returnA -< (x,v) integralVelSF :: Force -> Mass -> SF Double Double integralVelSF force mass = proc v0 -> do t1 <- integral -< 0.5 * (force/mass) returnA -< v0 + t1 Now, let's the speed (velocity), force and the mass equal 1.0. And the initial potion equal zero. Then using the "embed" function we get that, *Main> embed (integralCoordSF 1.0 1.0) ((0.0,1.0),[(0.1,Nothing),(0.1,Nothing)]) [(0.0,1.0),(0.1,1.05),(0.20500000000000002,1.1)] According to the algorithm, if dt = 0.1 then v = 1.0 + integral (0.5 * 1.0 * recip 1.0) = 1.05 in agreement with the algorithm. But let's see about the position x = 0 + integral (v) Using the formula of step 2, the position should be equal to 0.105, but the result given by embed is 0.1. As a beginner certainly and missing a lot of concepts and details, can someone please explain me what's going on here? Thank you for your help! Felipe Z
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe