(* State-space representation of a linear system. [a], [b], [c] and [d] *)
(* are matrices. *)

open Arrays

let node discrete_state_space(l)(m)(r)(x0)(a)(b)(c)(d)(u) = y where
  rec
    x = const(l)(x0) fby sum(l)(mvproduct(l)(l)(a,x), mvproduct(l)(m)(b,u))
  and
    y = sum(r)(mvproduct(r)(l)(c,x), mvproduct(r)(m)(d,u))

let node discrete_state_space_0(l)(m)(r)(x0)(a)(b)(c)(d)(u) = y where
  rec
    x = const(l)(x0) fby sum(l)(mvproduct(l)(l)(a,x), mvproduct(l)(m)(b,u))
  and
      y = mvproduct(r)(l)(c,x)