feat (exm): van der pol example

This commit is contained in:
Henri Saudubray 2025-04-29 10:42:49 +02:00
parent 8497091d0c
commit 9a0d22e880
Signed by: hms
GPG key ID: 7065F57ED8856128
3 changed files with 79 additions and 11 deletions

View file

@ -12,7 +12,7 @@ let of_array = Bigarray.Array1.of_array Bigarray.Float64 Bigarray.c_layout
type state =
{ zin : Zls.zarray;
l_x : Zls.carray; (* [h';h;x';x] *)
lx : Zls.carray; (* [h';h;x';x] *)
i : bool }
let g = -9.81
@ -30,16 +30,16 @@ let bouncing_ball () =
begin yd.{0} <- 0.0; yd.{1} <- 0.0; yd.{2} <- 0.0; yd.{3} <- 0.0 end in
let fzer _ (y: Zls.carray) (zout: Zls.carray) = zout.{0} <- -. y.{1} in
let fout _ (y: Zls.carray): Zls.carray = of_array [| y.{1} |] in
let step ({ zin; l_x; _ } as s) _ : Zls.carray * state =
let l_x = if zin.{0} = 1l then
of_array [| -. 0.8 *. l_x.{0}; 0.0; l_x.{2}; l_x.{3} |] else l_x in
of_array [| s.l_x.{1} |], { zin = zfalse; l_x; i = false } in
let cget s = s.l_x in
let cset s l_x = { s with l_x } in
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
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; l_x = 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