README.md 1.69 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# `pyStateSpace`

`pyStateSpace` is a package for simulating  a model using state space variables.

## System modeling

A system is described by its state-space variables `x`. The dynamics are described by the rate of change of those variables `dx/dt`.

A system can respond to inputs `u`. The observable measurements of the system are its outputs `y`.

In the general case, with no time invariance and linearity constraints:

```
dx/dt   = function(time, x, u)  --  (1)

y       = function(time, x, u)  --  (2)
```

The value of `x` at each time is found by integrating `(1)` over the time step.

## API

All classes adhere to the `scikit-learn Estimator` API with a `predict(t: np.ndarray, x0:np.ndarray, u: np.ndarray) -> Tuple[np.ndarray, np.ndarray]` method. 

All classes have these methods:

* `dxdt(time: float, x: np.ndarray, u: np.ndarray) -> np.ndarray`
* `y(time: float, x: np.ndarray, u: np.ndarray) -> np.ndarray`
* `predict(t: np.ndarray, x0:np.ndarray, u: np.ndarray) -> Tuple[np.ndarray, np.ndarray]` The return value is a tuple of an array of state variables and an array of output variables `(x, y)`.

Where `x`, `x0`, and `u` are vectors. `x0` is the initial state.

Three classes are defined:

### `Trapezoid`

37
Uses trapezoid integration rule to integrate `(1)`. `dxdt` and `y` methods can be overridden or provided as arguments.
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

### `LTISystem`

Same as `Trapezoid` but explicitly accepts linear time-invarnant system matrices `A, B, C, D` such that:

```
dx/dt   =   Ax + Bu
y       =   Cx + Du
```

No methods need to be overridden.

### `SS_ODE`

An alternative to `Trapezoid` that uses `scipy`'s `odeint` function to integrate `dx/dt`. `dxdt` and `y` methods can be overridden or provided as arguments.