type saturation = Upper | Between | Lower
let node forward_euler(t)(k, x0, u) = output where
rec output = x0 fby (output +. (k *. t) *. u)
let node backward_euler(t)(k, x0, u) = output where
rec output = x0 -> pre(output) +. k *. t *. u
let node trapezoidal_fixed(t)(k, x0, u) = output where
rec x = x0 fby (y +. gain *. u)
and y = x +. gain *. u
and gain = k *. t /. 2.0
and output = y
let node trapezoidal_variable_step(t)(k, x0, u) = output where
rec x = x0 fby y
and y = x +. gain *. (u +. u fby u)
and gain = k *. t /. 2.0
and output = y
let node forward_euler_complete(t)(upper, lower, res, k, x0, u) =
(output, sport, saturation) where
rec sport = x0 fby (output +. k *. t *. u)
and v = if res then x0 else sport
and (output, saturation) =
if v < lower then lower, Lower
else if v > upper then upper, Upper else v, Between
let node backward_euler_complete(t)(upper, lower, res, k, x0, u) =
(output, state_port, saturation) where
rec state_port = x0 -> pre(output) +. k *. t *. u
and v = if res then x0 else state_port
and output, saturation =
if v < lower then lower, Lower else if v > upper then upper, Upper
else v, Between
let node int(t)(k, x0, u) = forward_euler(t)(k, x0, u)
let node derivative(h)(k, u) = 0.0 -> k *. (u -. pre(u)) /. h
let node forward_euler_reset(t)(k, x0, res, u) = o where
rec reset
o = forward_euler(t)(k, x0, u)
every res