/* model of a bouncing ball. the ball can be elastic, in which case it loses half its velocity at each bounce, or inelastic, in which case it behaves like a spring with spring constant k and damping constant e. The model selection can be done by setting Compress or NoCompress in the basic model, which also incorparates the dynamics of the ball in the air. */ ht = 10, ht' = 0, sample(ht), always {m = 1, g = 10, k = 10000, e = 10}, always { Compress, cont(ht), if ht > 0 then ht'' = -g // free fall else Bounce() }, always { Bounce = (){ if Compress then SpringBounce(), if NoCompress then InelasticBounce() }, InelasticBounce = (){ ht' = - 0.5 * prev(ht') }, SpringBounce = (){ ht'' + e * ht' + k * ht + g = 0 } }