# ctrb

Controllability matrix

## Syntax

```Co = ctrb(A,B) Co = ctrb(sys) ```

## Description

`Co = ctrb(A,B)` returns the controllability matrix:

`$Co=\left[\begin{array}{ccccc}B& AB& {A}^{2}B& \dots & {A}^{n-1}B\end{array}\right]$`

where A is an n-by-n matrix, B is an n-by-m matrix, and Co has n rows and nm columns.

`Co = ctrb(sys)` calculates the controllability matrix of the state-space LTI object `sys`. This syntax is equivalent to:

```Co = ctrb(sys.A,sys.B); ```

The system is controllable if `Co` has full rank n.

## Examples

collapse all

Define `A` and `B` matrices.

```A = [1 1; 4 -2]; B = [1 -1; 1 -1];```

Compute controllability matrix.

`Co = ctrb(A,B);`

Determine the number of uncontrollable states.

`unco = length(A) - rank(Co)`
```unco = 1 ```

The uncontrollable state indicates that `Co` does not have full rank 2. Therefore the system is not controllable.

## Limitations

Estimating the rank of the controllability matrix is ill-conditioned; that is, it is very sensitive to roundoff errors and errors in the data. An indication of this can be seen from this simple example.

`$A=\begin{array}{cc}\left[\begin{array}{cc}1& \delta \\ 0& 1\end{array}\right],& B=\left[\begin{array}{l}1\\ \delta \end{array}\right]\end{array}$`

This pair is controllable if $\delta \ne 0$ but if $\delta <\sqrt{eps}$, where eps is the relative machine precision. `ctrb(A,B)` returns

`$\left[\begin{array}{cc}B& AB\end{array}\right]=\left[\begin{array}{cc}1& 1\\ \delta & \delta \end{array}\right]$`

which is not full rank. For cases like these, it is better to determine the controllability of a system using `ctrbf`.