(* Ball rolling on a cosine curve. *) (* Illustrates the impact of an observer on the simulation. *) let g = 9.81 let mu = 0.5 (* Friction coefficient. *) let hybrid ball(v0) = (x, v) where rec der x = v init 0.0 and der v = a *. (cos x) init v0 and a = g *. (sin x) -. mu *. v /. (cos x) let hybrid vdp_c(mu) = (x, y) where rec der x = y init 1.0 and der y = (mu *. (1.0 -. (x *. x)) *. y) -. x init 1.0 let hybrid print(p)(t, x, v, x', y) = () where present(period(p)) -> do () = print_endline(String.concat ",\t\t" (List.map string_of_float [t;x;v;x';y])) done (* Changing the period for [print] changes the result. *) let hybrid main () = () where rec der t = 1.0 init 0.0 and (x, v) = ball(2.953) and (x', y) = vdp_c(0.5) and () = print(0.5)(t, x, v, x', y) (* let input _ = 2.953 let node print_discrete (now, (x, v)) = print_endline (String.concat ",\t\t" (List.map string_of_float [now;x;v])) let ball_discrete = Solve.solve_sundials(ball) let node main_discrete () = let input = Some (Solve.make(30.0, input)) fby None in let o = run ball_discrete input in Solve.period'_t 1.0 print_discrete o *)