21 lines
598 B
Text
21 lines
598 B
Text
|
|
let dt = 0.001
|
|
let g = 9.81
|
|
|
|
let node f_integr (x0, x') = x where
|
|
rec x = x0 -> pre (x +. x' *. dt)
|
|
let node b_integr (x0, x') = x where
|
|
rec x = x0 -> (pre x) +. x' *. dt
|
|
|
|
let node bouncing_ball (p0, v0) = p where
|
|
rec p = reset f_integr (q, v) every z
|
|
and v = reset b_integr (w, -. g) every z
|
|
and q = p0 -> 0.0 and w = v0 -> -0.8 *. (pre v)
|
|
and z = false fby (p < 0.0)
|
|
|
|
let node main () =
|
|
let rec t = 0.0 fby (dt +. t) in
|
|
let p = bouncing_ball (5.0, 0.0) in
|
|
match t <= 10.0 with
|
|
| true -> (print_float t; print_string "\t"; print_float p; print_newline ())
|
|
| false -> ()
|