# modalreal

Compute modal state-space realization

Since R2023b

## Syntax

``[msys,blks] = modalreal(sys)``
``[msys,blks,TL,TR] = modalreal(sys)``
``[___] = modalreal(sys,Name=Value)``

## Description

example

````[msys,blks] = modalreal(sys)` returns a modal realization `msys` of an LTI model `sys`. This is a realization where A or (A,E) are block diagonal and each block corresponds to a real pole, a complex pair, or a cluster of repeated poles. `blks` is a vector containing block sizes down the diagonal.```

example

````[msys,blks,TL,TR] = modalreal(sys)` also returns the block-diagonalizing transformations `TL` and `TR`.```

example

````[___] = modalreal(sys,Name=Value)` specifies options for controlling the block size and normalizing 2-by-2 blocks associated with complex pairs.```

## Examples

collapse all

`pendulumCartSSModel.mat` contains the state-space model of an inverted pendulum on a cart where the outputs are the cart displacement $\mathit{x}$ and the pendulum angle $\theta$. The control input `u` is the horizontal force on the cart.

`$\begin{array}{l}\left[\begin{array}{c}\underset{}{\overset{˙}{x}}\\ \underset{}{\overset{¨}{x}}\\ \underset{}{\overset{˙}{\theta }}\\ \underset{}{\overset{¨}{\theta }}\end{array}\right]\phantom{\rule{0.2777777777777778em}{0ex}}=\phantom{\rule{0.2777777777777778em}{0ex}}\left[\begin{array}{cccc}0& 1& 0& 0\\ 0& -0.1& 3& 0\\ 0& 0& 0& 1\\ 0& -0.5& 30& 0\end{array}\right]\left[\begin{array}{c}x\\ \underset{}{\overset{˙}{x}}\\ \theta \\ \underset{}{\overset{˙}{\theta }}\end{array}\right]+\left[\begin{array}{c}0\\ 2\\ 0\\ 5\end{array}\right]u\\ \phantom{\rule{0.2777777777777778em}{0ex}}\phantom{\rule{0.2777777777777778em}{0ex}}\phantom{\rule{0.2777777777777778em}{0ex}}\phantom{\rule{0.2777777777777778em}{0ex}}\phantom{\rule{0.2777777777777778em}{0ex}}y\phantom{\rule{0.2777777777777778em}{0ex}}=\phantom{\rule{0.2777777777777778em}{0ex}}\left[\begin{array}{cccc}1& 0& 0& 0\\ 0& 0& 1& 0\end{array}\right]\left[\begin{array}{c}x\\ \underset{}{\overset{˙}{x}}\\ \theta \\ \underset{}{\overset{˙}{\theta }}\end{array}\right]+\left[\begin{array}{c}0\\ 0\end{array}\right]u\end{array}$`

First, load the state-space model `sys` to the workspace.

`load('pendulumCartSSModel.mat','sys');`

Convert `sys` to modal form and extract the block sizes.

`[msys,blks,TL,TR] = modalreal(sys)`
```msys = A = x1 x2 x3 x4 x1 0 0 0 0 x2 0 -0.05 0 0 x3 0 0 -5.503 0 x4 0 0 0 5.453 B = u1 x1 1.875 x2 6.298 x3 12.8 x4 12.05 C = x1 x2 x3 x4 y1 16 -4.763 -0.003696 0.003652 y2 0 0.003969 -0.03663 0.03685 D = u1 y1 0 y2 0 Continuous-time state-space model. ```
```blks = 4×1 1 1 1 1 ```
```TL = 4×4 0.0625 1.2500 -0.0000 -0.1250 0 4.1986 0.0210 -0.4199 0 0.2285 -13.5873 2.4693 0 -0.2251 13.6287 2.4995 ```
```TR = 4×4 16.0000 -4.7631 -0.0037 0.0037 0 0.2381 0.0203 0.0199 0 0.0040 -0.0366 0.0369 0 -0.0002 0.2015 0.2009 ```

`msys` is the modal realization of `sys`, `blks` represents the block sizes down the diagonal, and `TL` and `TR` represent the block-diagonalizing transformation matrices.

For this example, consider the following system with doubled poles and clusters of close poles:

`$sys\left(s\right)=100\frac{\left(s-1\right)\left(s+1\right)}{s\left(s+10\right)\left(s+10.0001\right){\left(s-\left(1+i\right)\right)}^{2}{\left(s-\left(1-i\right)\right)}^{2}}$`

Create a `zpk` model of this system and obtain a modal realization using the function `modalreal`.

```sys = zpk([1 -1],[0 -10 -10.0001 1+1i 1-1i 1+1i 1-1i],100); [msys1,blks1] = modalreal(sys); blks1```
```blks1 = 3×1 1 4 2 ```
`msys1.A`
```ans = 7×7 0 0 0 0 0 0 0 0 1.0000 2.1220 0 0 0 0 0 -0.4713 1.0000 1.5296 0 0 0 0 0 0 1.0000 1.8439 0 0 0 0 0 -0.5423 1.0000 0 0 0 0 0 0 0 -10.0000 4.0571 0 0 0 0 0 0 -10.0001 ```
`msys1.B`
```ans = 7×1 0.1600 -0.0052 0.0201 -0.0975 0.2884 0 4.0095 ```

`sys` has a pair of poles at `s` `=` `-10` and `s` `=` `-10.0001`, and two complex poles of multiplicity 2 at `s` `=` `1+i` and `s` `=` `1-i`. As a result, the modal form `msys1` is a state-space model with a block of size 2 for the two poles near `s` `=` `-10`, and a block of size 4 for the complex eigenvalues.

Now, separate the two poles near `s` `=` `-10` by increasing the condition number of the block-diagonalizing transformation. Set `SepTol` to `1e-10` for this example.

```[msys2,blks2] = modalreal(sys,SepTol=1e-10); blks2```
```blks2 = 4×1 1 4 1 1 ```
`msys2.A`
```ans = 7×7 0 0 0 0 0 0 0 0 1.0000 2.1220 0 0 0 0 0 -0.4713 1.0000 1.5296 0 0 0 0 0 0 1.0000 1.8439 0 0 0 0 0 -0.5423 1.0000 0 0 0 0 0 0 0 -10.0000 0 0 0 0 0 0 0 -10.0001 ```
`msys2.B`
```ans = 7×1 105 × 0.0000 -0.0000 0.0000 -0.0000 0.0000 1.6267 1.6267 ```

The `A` matrix of `msys2` includes separate diagonal elements for the poles near `s` `=` `-10`. Increasing the condition number results in some very large values in the `B` matrix.

For this example, consider the following system with complex pair poles and clusters of close poles:

`$sys\left(s\right)=100\frac{\left(s-1\right)\left(s+1\right)}{s\left(s+10\right)\left(s+10.0001\right){\left(s-\left(3+4i\right)\right)}^{2}}$`

Create a `zpk` model of this system and obtain a modal realization using the function `modalreal`.

```sys = zpk([1 -1],[0 -10 -10.0001 3+4i 3-4i],100); [msys1,blks1] = modalreal(sys); blks1```
```blks1 = 3×1 1 2 2 ```
`msys1.A`
```ans = 5×5 0 0 0 0 0 0 3.0000 8.7637 0 0 0 -1.8257 3.0000 0 0 0 0 0 -10.0000 8.8001 0 0 0 0 -10.0001 ```

`msys1` is a state-space model with a block of sizes 2 for the two poles near `s` `=` `-10`, and a pair of complex poles at `s` `=` 3`+4i` and `s` `=` 3`-4i`.

You can normalize the values of 2-by-2 blocks to show the actual pole values using the `Normalize` option. Additionally, relax the relative accuracy of the block diagonalizing transformation to separate the block near `s` `=` `-10`.

```[msys2,blks2] = modalreal(sys,Normalize=true,SepTol=1e-10); blks2```
```blks2 = 4×1 1 2 1 1 ```
`msys2.A`
```ans = 5×5 0 0 0 0 0 0 3.0000 4.0000 0 0 0 -4.0000 3.0000 0 0 0 0 0 -10.0000 0 0 0 0 0 -10.0001 ```

For complex poles, this option normalizes the 2-by-2 block of complex poles $\mathit{a}±\mathit{bi}$ to $\left[\begin{array}{cc}\mathit{a}& \mathit{b}\\ -\mathit{b}& \mathit{a}\end{array}\right]$.

## Input Arguments

collapse all

Dynamic system, specified as a SISO, or MIMO dynamic system model. Dynamic systems that you can use include:

You cannot use frequency-response data models such as `frd` models.

### Name-Value Arguments

Specify optional pairs of arguments as `Name1=Value1,...,NameN=ValueN`, where `Name` is the argument name and `Value` is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: `[msys,blks] = modalreal(sys,Normalize=true)`

Relative accuracy of block diagonalization, specified as a scalar between 0 and 1.

This option limits the condition number of the block diagonalizing transformation to roughly `SepTol`/`eps`. Increasing `SepTol` helps yield smaller blocks at the expense of accuracy.

Normalize 1-by-1 and 2-by-2 diagonal blocks, specified as a logical `0` (`false`) or `1` (`true`).

When `Normalize` is `true`, the function normalizes the block to show the pole values.

• For explicit models, the function normalizes 2-by-2 blocks associated with complex pairs a±jb to $\left[\begin{array}{cc}a& b\\ -b& a\end{array}\right]$.

• For descriptor models, the function normalizes

• 1-by-1 blocks to Aj = a, Ej = 1.

• 2-by-2 blocks to Aj = $\left[\begin{array}{cc}a& b\\ -b& a\end{array}\right]$, Ej = I.

## Output Arguments

collapse all

Modal state-space realization of the dynamic model, returned as an `ss` model object. `msys` is a realization where A or (A,E) are block diagonal and each block corresponds to a real pole, a complex pair, or a cluster of repeated poles.

Block sizes in the block-diagonal realization, returned as a vector.

Left-side matrix of the block-diagonalizing transformation, returned as a matrix with dimensions Nx-by-Nx, where Nx is the number of states in the model `sys`.

The algorithm transforms the state-space realization (A, B, C, D, E) of a model to block diagonal matrices (Am, Bm, Cm, Dm, Em) given by:

• For explicit state-space models

`$\begin{array}{l}\begin{array}{cc}{A}_{m}={T}_{L}A{T}_{R},& {B}_{m}={T}_{L}B,\end{array}\\ \begin{array}{ccc}{C}_{m}=C{T}_{R},& {D}_{m}=D,& E={T}_{L}{T}_{R}=I\end{array}\end{array}$`
• For descriptor state-space models

`$\begin{array}{l}\begin{array}{cc}{A}_{m}={T}_{L}A{T}_{R},& {B}_{m}={T}_{L}B,\end{array}\\ \begin{array}{ccc}{C}_{m}=C{T}_{R},& {D}_{m}=D,& {E}_{m}={T}_{L}E{T}_{R}\end{array}\end{array}$`

The function returns an empty value `[]` for this argument when the input model `sys` is not a state-space model.

Right-side matrix of the block-diagonalizing transformation, returned as a matrix with dimensions Nx-by-Nx, where Nx is the number of states in the model `sys`.The algorithm transforms the state-space realization (A, B, C, D, E) of a model to block diagonal matrices (Am, Bm, Cm, Dm, Em) given by:

• For explicit state-space models

`$\begin{array}{l}\begin{array}{cc}{A}_{m}={T}_{L}A{T}_{R},& {B}_{m}={T}_{L}B,\end{array}\\ \begin{array}{ccc}{C}_{m}=C{T}_{R},& {D}_{m}=D,& E={T}_{L}{T}_{R}=I\end{array}\end{array}$`
• For descriptor state-space models

`$\begin{array}{l}\begin{array}{cc}{A}_{m}={T}_{L}A{T}_{R},& {B}_{m}={T}_{L}B,\end{array}\\ \begin{array}{ccc}{C}_{m}=C{T}_{R},& {D}_{m}=D,& {E}_{m}={T}_{L}E{T}_{R}\end{array}\end{array}$`

The function returns an empty value `[]` for this argument when the input model `sys` is not a state-space model.

## Version History

Introduced in R2023b