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