pub struct StateSpace {
pub a: Vec<Vec<f64>>,
pub b: Vec<Vec<f64>>,
pub c: Vec<Vec<f64>>,
pub d: Vec<Vec<f64>>,
pub e: Option<Vec<Vec<f64>>>,
}Fields§
§a: Vec<Vec<f64>>n x n dynamics matrix.
b: Vec<Vec<f64>>n x m input matrix (m = number of inputs).
c: Vec<Vec<f64>>p x n output matrix (p = number of outputs).
d: Vec<Vec<f64>>p x m feedthrough matrix.
e: Option<Vec<Vec<f64>>>n x n descriptor matrix. None means the identity (ordinary state-space); an explicit
non-identity e is the “Descriptor State-Space” case.
Implementations§
Source§impl StateSpace
impl StateSpace
Sourcepub fn new(
a: Vec<Vec<f64>>,
b: Vec<Vec<f64>>,
c: Vec<Vec<f64>>,
d: Vec<Vec<f64>>,
e: Option<Vec<Vec<f64>>>,
) -> Result<Self, StateSpaceError>
pub fn new( a: Vec<Vec<f64>>, b: Vec<Vec<f64>>, c: Vec<Vec<f64>>, d: Vec<Vec<f64>>, e: Option<Vec<Vec<f64>>>, ) -> Result<Self, StateSpaceError>
Validates e (if given) is invertible, then returns the assembled system. Every
StateSpace::derivative call downstream relies on this having already been checked —
see StateSpaceError::NonInvertibleDescriptorMatrix’s own doc comment.
pub fn states(&self) -> usize
pub fn inputs(&self) -> usize
pub fn outputs(&self) -> usize
Sourcepub fn derivative(&self, x: &[f64], u: &[f64]) -> Vec<f64>
pub fn derivative(&self, x: &[f64], u: &[f64]) -> Vec<f64>
dx/dt at the given (x, u), solving E * dx/dt = A*x + B*u for dx/dt when a
non-identity descriptor matrix e is present (via the same dense Gauss-Jordan solve
dae-runtime uses — small, hand-checkable, faer deferred until it’s actually needed;
see that crate’s linsolve module doc for the same reasoning applied here).
Sourcepub fn rk4_step(&self, x: &[f64], u: &[f64], dt: f64) -> Vec<f64>
pub fn rk4_step(&self, x: &[f64], u: &[f64], dt: f64) -> Vec<f64>
Advances one RK4 step of size dt, holding u constant over the step (zero-order
hold — matches how a discrete-timestep circuit/controller simulation would drive this
block in dae-runtime’s eventual timestep loop). Returns the new state; call
StateSpace::output separately for y at the new state.
Sourcepub fn discrete_step(&self, x: &[f64], u: &[f64]) -> Vec<f64>
pub fn discrete_step(&self, x: &[f64], u: &[f64]) -> Vec<f64>
One step of a genuinely discrete-time system: x[i+1] = A*x[i] + B*u[i], plain
linear recursion, no RK4, no dt, no numerical integration at all — the discrete-domain
counterpart to Self::rk4_step. A/B here are already discrete-domain matrices,
given directly by the caller (this method does no continuous-to-discrete conversion of
its own) — see book/dev-guide/src/discrete-time-blocks.md. dae-runtime calls this
once per declared sample period instead of once per circuit step, the same zero-order-
hold accumulator cscript/pyblock already use. Ignores self.e entirely — a
descriptor matrix has no meaning for a plain discrete recursion (there is no dx/dt to
solve E against here).