Struct state_space::state_space::StateSpace
source · pub struct StateSpace<F: Float, const VARCOUNT: usize>where
[[F; VARCOUNT]; VARCOUNT]: SquareMatrix,
[[F; 1]; VARCOUNT]: Matrix,
[[F; VARCOUNT]; 1]: Matrix,{
pub a: [[F; VARCOUNT]; VARCOUNT],
pub b: [[F; 1]; VARCOUNT],
pub c: [[F; VARCOUNT]; 1],
pub d: F,
}Expand description
State-space equation matrices A, B, C and D contained in one structure
Fields§
§a: [[F; VARCOUNT]; VARCOUNT]§b: [[F; 1]; VARCOUNT]§c: [[F; VARCOUNT]; 1]§d: FImplementations§
source§impl<F: Float, const VARCOUNT: usize> StateSpace<F, VARCOUNT>where
[[F; VARCOUNT]; VARCOUNT]: SquareMatrix,
[[F; 1]; VARCOUNT]: Matrix,
[[F; VARCOUNT]; 1]: Matrix,
impl<F: Float, const VARCOUNT: usize> StateSpace<F, VARCOUNT>where
[[F; VARCOUNT]; VARCOUNT]: SquareMatrix,
[[F; 1]; VARCOUNT]: Matrix,
[[F; VARCOUNT]; 1]: Matrix,
sourcepub fn new_control_canonical_form(a: [F; VARCOUNT], b: [F; VARCOUNT]) -> Self
pub fn new_control_canonical_form(a: [F; VARCOUNT], b: [F; VARCOUNT]) -> Self
Creates a new state-space struct in control-canonical form
Arguments
a- Transfer function denominator polynomialb- Transfer function enumerator polynomial
Examples
let a = [1.0, 2.0, 3.0];
let b = [4.0, 5.0, 6.0];
let ss = StateSpace::new_control_canonical_form(a, b);
assert_eq!(ss.a, [
[-a[0], -a[1], -a[2]],
[1.0, 0.0, 0.0],
[0.0, 1.0, 0.0]
]);
assert_eq!(ss.b, [
[1.0],
[0.0],
[0.0]
]);
assert_eq!(ss.c, [
[b[0], b[1], b[2]]
]);
assert_eq!(ss.d, 0.0);sourcepub fn new_observer_canonical_form(a: [F; VARCOUNT], b: [F; VARCOUNT]) -> Self
pub fn new_observer_canonical_form(a: [F; VARCOUNT], b: [F; VARCOUNT]) -> Self
Creates a new state-space struct in observer-canonical form
Arguments
a- Transfer function denominator polynomialb- Transfer function enumerator polynomial
Examples
let a = [1.0, 2.0, 3.0];
let b = [4.0, 5.0, 6.0];
let ss = StateSpace::new_observer_canonical_form(a, b);
assert_eq!(ss.a, [
[-a[0], 1.0, 0.0],
[-a[1], 0.0, 1.0],
[-a[2], 0.0, 0.0]
]);
assert_eq!(ss.b, [
[b[0]],
[b[1]],
[b[2]]
]);
assert_eq!(ss.c, [
[1.0, 0.0, 0.0]
]);
assert_eq!(ss.d, 0.0);sourcepub fn controllability(&self) -> [[F; VARCOUNT]; VARCOUNT]
pub fn controllability(&self) -> [[F; VARCOUNT]; VARCOUNT]
Returns the controllability-matrix of the state-space equation
𝒞
Examples
let cc = ss.controllability()sourcepub fn is_controllable(&self) -> boolwhere
[[F; VARCOUNT]; VARCOUNT]: Det<Output = F>,
pub fn is_controllable(&self) -> boolwhere
[[F; VARCOUNT]; VARCOUNT]: Det<Output = F>,
sourcepub fn observability(&self) -> [[F; VARCOUNT]; VARCOUNT]
pub fn observability(&self) -> [[F; VARCOUNT]; VARCOUNT]
sourcepub fn is_observable(&self) -> boolwhere
[[F; VARCOUNT]; VARCOUNT]: Det<Output = F>,
pub fn is_observable(&self) -> boolwhere
[[F; VARCOUNT]; VARCOUNT]: Det<Output = F>,
sourcepub fn transform_state(&self, t: [[F; VARCOUNT]; VARCOUNT]) -> Option<Self>where
[[F; VARCOUNT]; VARCOUNT]: MInv<Output = [[F; VARCOUNT]; VARCOUNT]>,
pub fn transform_state(&self, t: [[F; VARCOUNT]; VARCOUNT]) -> Option<Self>where
[[F; VARCOUNT]; VARCOUNT]: MInv<Output = [[F; VARCOUNT]; VARCOUNT]>,
sourcepub fn transform_into_control_canonical_form(&self) -> Option<Self>where
[[F; VARCOUNT]; VARCOUNT]: MInv<Output = [[F; VARCOUNT]; VARCOUNT]>,
pub fn transform_into_control_canonical_form(&self) -> Option<Self>where
[[F; VARCOUNT]; VARCOUNT]: MInv<Output = [[F; VARCOUNT]; VARCOUNT]>,
Transforms any state-space system into control-canonical form
Examples
let ssc = ss.transform_into_control_canonical_form()sourcepub fn transform_into_observer_canonical_form(&self) -> Option<Self>where
[[F; VARCOUNT]; VARCOUNT]: MInv<Output = [[F; VARCOUNT]; VARCOUNT]>,
pub fn transform_into_observer_canonical_form(&self) -> Option<Self>where
[[F; VARCOUNT]; VARCOUNT]: MInv<Output = [[F; VARCOUNT]; VARCOUNT]>,
Transforms any state-space system into observer-canonical form
Examples
let sso = ss.transform_into_observer_canonical_form()sourcepub fn dxdt(&self, x: [[F; 1]; VARCOUNT], u: F) -> [[F; 1]; VARCOUNT]
pub fn dxdt(&self, x: [[F; 1]; VARCOUNT], u: F) -> [[F; 1]; VARCOUNT]
Returns the derivative of the internal variables according to the state-space equations
Arguments
x- The state of the internal state-space variables organized in a collumn-vectoru- The system input state
Examples
let dt = 0.0001;
let mut x = [
[0.0],
[0.0]
];
let mut u = 0.0;
for _ in 0..10000
{
x = x.add(ss.dxdt(x, u).mul(dt))
u = 1.0;
}
let y_ss = ss.y(x, u);
// Steady state error:
let e_ss = y_ss - u;sourcepub fn y(&self, x: [[F; 1]; VARCOUNT], u: F) -> F
pub fn y(&self, x: [[F; 1]; VARCOUNT], u: F) -> F
Returns the output state according to the state-space equations
Arguments
x- The state of the internal state-space variables organized in a collumn-vectoru- The system input state
Examples
let dt = 0.0001;
let mut x = [[0.0]; 2];
let mut u = 0.0;
for _ in 0..10000
{
x = x.add(ss.dxdt(x, u).mul(dt));
u = 1.0;
}
let y_ss = ss.y(x, u);
// Steady state error:
let e_ss = y_ss - u;