feat (notes): reorganise and update (and some formatting)
This commit is contained in:
parent
3b5e01b163
commit
dd6152833f
6 changed files with 211 additions and 209 deletions
|
|
@ -33,13 +33,13 @@ let bouncing_ball () =
|
|||
let step ({ zin; lx; _ } as s) _ : Zls.carray * state =
|
||||
let lx = if zin.{0} = 1l then
|
||||
of_array [| -. 0.8 *. lx.{0}; 0.0; lx.{2}; lx.{3} |] else lx in
|
||||
of_array [| s.lx.{1} |], { zin = zfalse; lx; i = false } in
|
||||
of_array [| s.lx.{1} |], { zin=zfalse; lx; i=false } in
|
||||
let cget s = s.lx in
|
||||
let cset s lx = { s with lx } in
|
||||
let zset s zin = { s with zin } in
|
||||
let yd = Zls.cmake 4 in
|
||||
let zout = Zls.cmake 1 in
|
||||
let state = { zin = zfalse; lx = of_array [|y'0;y0;x'0;x0|]; i = true } in
|
||||
let state = { zin=zfalse; lx=of_array [|y'0;y0;x'0;x0|]; i=true } in
|
||||
let reset _ _ = state in
|
||||
let jump _ = true in
|
||||
let zsize = 1 in
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ let zsize = 1
|
|||
let fzer _ _ _ = zout
|
||||
let fout _ _ y = of_array [| y.{0}; y.{1}; y.{2} |]
|
||||
let cget s = s.sx
|
||||
let cset s lx = { s with sx = lx }
|
||||
let cset s lx = { s with sx=lx }
|
||||
let zset s _ = s
|
||||
let jump _ = true
|
||||
let horizon _ = max_float
|
||||
|
|
@ -25,11 +25,11 @@ let sinus_cosinus theta0 omega =
|
|||
yd.{0} <- omega *. y.{1}; yd.{1} <- -.omega *. y.{0}; yd.{2} <- 1.0; yd in
|
||||
let step { si; sx } _ =
|
||||
let sx = if si then of_array [| sin0; cos0; 0.0 |] else sx in
|
||||
of_array [| sx.{0}; sx.{1}; sx.{2} |], { sx; si = false } in
|
||||
let state = { sx = of_array [| sin0; cos0; 0.0 |]; si = true } in
|
||||
of_array [| sx.{0}; sx.{1}; sx.{2} |], { sx; si=false } in
|
||||
let state = { sx=of_array [| sin0; cos0; 0.0 |]; si=true } in
|
||||
let reset _ _ = state in
|
||||
HNode {
|
||||
state; fder; fzer; fout; step; horizon; cset; cget; zset; zsize; reset; jump
|
||||
state; fder; fzer; fout; step; horizon; cset; cget; zset; zsize; reset; jump
|
||||
}
|
||||
|
||||
let errmsg_invalid = "Invalid arguments to model (needed: 2 floats)"
|
||||
|
|
|
|||
29
exm/sqrt.ml
29
exm/sqrt.ml
|
|
@ -8,7 +8,7 @@ type s = Good | Bad
|
|||
|
||||
let with_nan = false
|
||||
|
||||
type state =
|
||||
type state =
|
||||
{ s_auto: s; (* active state of the automaton *)
|
||||
s_pos : carray;
|
||||
s_zin : zarray;
|
||||
|
|
@ -19,7 +19,7 @@ let sqrt () =
|
|||
let fder s y yd =
|
||||
yd.{0} <- -1.0;
|
||||
match s.s_auto with
|
||||
| Good ->
|
||||
| Good ->
|
||||
let o = if with_nan then sqrt y.{0}
|
||||
else if y.{0} >= 0.0 then sqrt y.{0} else 0.0 in
|
||||
yd.{1} <- o
|
||||
|
|
@ -27,9 +27,9 @@ let sqrt () =
|
|||
yd.{1} <- 0.0 in
|
||||
let fzero _ y zout = zout.{0} <- -. y.{0} in
|
||||
let fout state y =
|
||||
let o =
|
||||
let o =
|
||||
match state.s_auto with
|
||||
| Good -> let o =
|
||||
| Good -> let o =
|
||||
if with_nan then sqrt y.{0}
|
||||
else if y.{0} >= 0.0 then sqrt y.{0} else 0.0 in
|
||||
o
|
||||
|
|
@ -40,28 +40,27 @@ let sqrt () =
|
|||
| Good ->
|
||||
let o = if with_nan then sqrt s_pos.{0}
|
||||
else if s_pos.{0} >= 0.0 then sqrt s_pos.{0} else 0.0 in
|
||||
let state =
|
||||
if s_zin.{0} = 1l then { state with s_auto = Bad; s_encore = true }
|
||||
let state =
|
||||
if s_zin.{0} = 1l then { state with s_auto=Bad; s_encore=true }
|
||||
else state in
|
||||
let pos = of_array [| state.s_pos.{0}; state.s_pos.{1} |] in
|
||||
of_array [| o; state.s_pos.{0}; state.s_pos.{1} |],
|
||||
{ state with s_zin = zfalse; s_pos = pos }
|
||||
| Bad ->
|
||||
of_array [| o; state.s_pos.{0}; state.s_pos.{1} |],
|
||||
{ state with s_zin=zfalse; s_pos=pos }
|
||||
| Bad ->
|
||||
let o = 42.0 in
|
||||
let state = { state with s_encore = false;
|
||||
s_pos =
|
||||
of_array [| s_pos.{0}; 0.0 |] } in
|
||||
let state = { state with s_encore=false;
|
||||
s_pos=of_array [| s_pos.{0}; 0.0 |] } in
|
||||
of_array [| o; state.s_pos.{0}; state.s_pos.{1} |], state in
|
||||
let cget { s_pos; _ } = s_pos in
|
||||
let cset s l_x = { s with s_pos = l_x } in
|
||||
let zset s zin = { s with s_zin = zin } in
|
||||
let cset s l_x = { s with s_pos=l_x } in
|
||||
let zset s zin = { s with s_zin=zin } in
|
||||
let yd = cmake 2 in
|
||||
let zout = cmake 1 in
|
||||
let zsize = 1 in
|
||||
let s_init =
|
||||
{ s_encore = false;
|
||||
s_auto = Good;
|
||||
s_pos = of_array [| 13.3; 0.0 |];
|
||||
s_pos = of_array [| 13.3; 0.0 |];
|
||||
s_zin = zmake 1 } in
|
||||
let reset _ _ = s_init in
|
||||
let jump _ = true in
|
||||
|
|
|
|||
|
|
@ -23,11 +23,11 @@ let fzer _ _ _ = zout
|
|||
let fout _ _ y = of_array [| y.{0}; y.{1} |]
|
||||
let step { i; lx } _ =
|
||||
let lx = if i then of_array [| x0; y0 |] else lx in
|
||||
of_array [| lx.{0}; lx.{1} |], { lx; i = false }
|
||||
of_array [| lx.{0}; lx.{1} |], { lx; i=false }
|
||||
let cget s = s.lx
|
||||
let cset s lx = { s with lx }
|
||||
let zset s _ = s
|
||||
let state = { lx = of_array [| x0; y0 |]; i = true }
|
||||
let state = { lx=of_array [| x0; y0 |]; i=true }
|
||||
let reset _ _ = state
|
||||
let jump _ = true
|
||||
let horizon _ = max_float
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue