# gram

Controllability and observability Gramians

## Syntax

``Wc = gram(sys,'c')``
``Wo = gram(sys,'o')``
``Rc = gram(sys,'cf')``
``Ro = gram(sys,'of')``
``W = gram(___,opt)``

## Description

Use `gram` to construct the controllability and observability Gramians. You can use Gramians to study the controllability and observability properties of state-space models and for model reduction [1]. They have better numerical properties than the controllability and observability matrices formed by `ctrb` and `obsv`.

````Wc = gram(sys,'c')` calculates the controllability Gramian of the state-space model `sys`.```
````Wo = gram(sys,'o')` calculates the observability Gramian of the state-space model `sys`.```
````Rc = gram(sys,'cf')` returns the Cholesky factor of the controllability Gramian.```
````Ro = gram(sys,'of')` returns the Cholesky factor of the observability Gramian.```
````W = gram(___,opt)` calculates time-limited or frequency-limited Gramians. `opt` is an option set that specifies time or frequency intervals for the computation. Create `opt` using the `gramOptions` command. ```

example

## Examples

collapse all

Compute the controllability Gramian of the following state-space model. Focus the computation on the frequency interval with the most energy.

`sys = ss([-.1 -1;1 0],[1;0],[0 1],0);`

The model contains a peak at 1 rad/s. Use `gramOptions` to specify an interval around that frequency.

```opt = gramOptions('FreqIntervals',[0.8 1.2]); gc = gram(sys,'c',opt)```
```gc = 2×2 4.2132 -0.0000 -0.0000 4.2433 ```

## Input Arguments

collapse all

Input model, specified as a state-space model or an array of state-space models.

The input model must be stable and without any internal delays. For descriptor state-space models, the matrix E must be nonsingular.

Option set for computing time-limited or frequency-limited Gramians, specified as a `gramOptions` object.

## Output Arguments

collapse all

Controllability or observability Gramian, returned as a matrix.

Cholesky factor of controllability or observability Gramian, returned as a matrix.

The Cholesky factors of Gramians are defined as follows:

• Controllability Gramian — ${W}_{c}={R}_{c}^{T}{R}_{c}$

• Observability Gramian — ${W}_{o}={R}_{o}^{T}{R}_{o}$

## Limitations

The A matrix must be stable (all eigenvalues have negative real part in continuous time, and magnitude strictly less than one in discrete time).

collapse all

### Controllability and Observability Gramians

Given the continuous-time state-space model

`$\begin{array}{l}\stackrel{˙}{x}=Ax+Bu\\ y=Cx+Du\end{array}$`

the controllability Gramian is defined by

`${W}_{c}={\int }_{0}^{\infty }{e}^{A\tau }B{B}^{T}{e}^{{A}^{T}\tau }d\tau$`

The controllability Gramian is positive definite if and only if (A, B) is controllable.

The observability Gramian is defined by

`${W}_{o}={\int }_{0}^{\infty }{e}^{{A}^{T}\tau }{C}^{T}C{e}^{A\tau }d\tau$`

The observability Gramian is positive definite if and only if (A, C) is observable.

The discrete-time counterparts of the controllability and observability Gramians are:

`$\begin{array}{cc}{W}_{c}=\sum _{k=0}^{\infty }{A}^{k}B{B}^{T}{\left({A}^{T}\right)}^{k},& {W}_{o}=\end{array}\sum _{k=0}^{\infty }{\left({A}^{T}\right)}^{k}{C}^{T}C{A}^{k}$`

Use time-limited or frequency-limited Gramians to examine the controllability or observability of states within particular time or frequency intervals. The definition of these Gramians is as described in [2].

## Algorithms

The controllability Gramian Wc is obtained by solving the continuous-time Lyapunov equation

`$A{W}_{c}+{W}_{c}{A}^{T}+B{B}^{T}=0$`

or its discrete-time counterpart

`$A{W}_{c}{A}^{T}-{W}_{c}+B{B}^{T}=0$`

Similarly, the observability Gramian Wo solves the Lyapunov equation

`${A}^{T}{W}_{o}+{W}_{o}A+{C}^{T}C=0$`

in continuous time, and the Lyapunov equation

`${A}^{T}{W}_{o}A-{W}_{o}+{C}^{T}C=0$`

in discrete time.

The computation of time-limited and frequency-limited Gramians is as described in [2].

## References

[1] Kailath, Thomas. Linear Systems. Prentice-Hall Information and System Science Series. Englewood Cliffs, N.J: Prentice-Hall, 1980.

[2] Gawronski, Wodek, and Jer-Nan Juang. “Model Reduction in Limited Time and Frequency Intervals.” International Journal of Systems Science 21, no. 2 (February 1990): 349–76. https://doi.org/10.1080/00207729008910366.

## Version History

Introduced before R2006a