-- Exercise 4.5 -- George C. Privon -- 2024-07-20 type R = Double type Derivative = (R -> R) -> R -> R type Time = R type Position = R type Velocity = R type Acceleration = R type PositionFunction = Time -> Position type VelocityFunction = Time -> Velocity type AccelerationFunction = Time -> Acceleration -- -- a function to take the numerical derivative, approximated for some dt derivative :: R -> Derivative derivative dt x t = (x (t + dt/2) - x (t - dt/2)) / dt pos1 :: PositionFunction pos1 t = if t < 0 then 0 else 5 * t**2 vel1Analytic :: VelocityFunction vel1Analytic t = if t < 0 then 0 else 10 * t acc1Analytic :: AccelerationFunction acc1Analytic t = if t < 0 then 0 else 10 vel1Numerical :: VelocityFunction vel1Numerical t = derivative 0.01 pos1 t acc1Numerical :: AccelerationFunction acc1Numerical t = derivative 0.01 (derivative 0.01 pos1 ) t -- Solution -- The numerical and analytic velocity functions seem to agree closely across -- the range, except when t~<0.001. -- The numerical acceleration function differs the most around t=0 but is -- in agreement across the rest of the range.