# inv

Inverse of symbolic matrix

## Syntax

``D = inv(A)``

## Description

example

````D = inv(A)` returns the inverse of a symbolic matrix `A`.```

## Examples

collapse all

Compute the inverse of a matrix of symbolic numbers.

```A = sym([2 -1 0; -1 2 -1; 0 -1 2]); D = inv(A)```
```D =  $\left(\begin{array}{ccc}\frac{3}{4}& \frac{1}{2}& \frac{1}{4}\\ \frac{1}{2}& 1& \frac{1}{2}\\ \frac{1}{4}& \frac{1}{2}& \frac{3}{4}\end{array}\right)$```

Compute the inverse of a matrix of symbolic scalar variables.

```syms a b c d A = [a b; c d]; D = inv(A)```
```D =  $\left(\begin{array}{cc}\frac{d}{a d-b c}& -\frac{b}{a d-b c}\\ -\frac{c}{a d-b c}& \frac{a}{a d-b c}\end{array}\right)$```

Compute the inverse of the Hilbert matrix that contains symbolic numbers.

`D = inv(sym(hilb(4)))`
```D =  $\left(\begin{array}{cccc}16& -120& 240& -140\\ -120& 1200& -2700& 1680\\ 240& -2700& 6480& -4200\\ -140& 1680& -4200& 2800\end{array}\right)$```

Find the inverse of a 4-by-4 block matrix

`$\mathbit{C}=\left[\begin{array}{cc}\mathbit{A}& {0}_{2,2}\\ {0}_{2,2}& \mathbit{B}\end{array}\right]$`

where $\mathbit{A}$ and $\mathbit{B}$ are 2-by-2 submatrices. The notation ${0}_{2,2}$ represents a 2-by-2 submatrix of zeros.

Use symbolic matrix variables to represent the submatrices in the block matrix.

```syms A B [2 2] matrix Z = symmatrix(zeros(2))```
`Z = ${\mathrm{0}}_{2,2}$`
`C = [A Z; Z B]`
```C =  $\left(\begin{array}{c}\begin{array}{cc}A& {\mathrm{0}}_{2,2}\end{array}\\ \begin{array}{cc}{\mathrm{0}}_{2,2}& B\end{array}\end{array}\right)$```

Find the inverse of the matrix $\mathbit{C}$.

`D = inv(C)`
```D =  ${\left(\begin{array}{c}\begin{array}{cc}A& {\mathrm{0}}_{2,2}\end{array}\\ \begin{array}{cc}{\mathrm{0}}_{2,2}& B\end{array}\end{array}\right)}^{-1}$```

To show the elements of the inverse matrix, convert the result from a symbolic matrix variable to symbolic scalar variables using `symmatrix2sym`.

`D1 = symmatrix2sym(D)`
```D1 =  ```

Compute the inverse of the matrix polynomial ${\mathit{a}}_{0\text{\hspace{0.17em}}}{\mathbit{I}}_{2}+{\mathit{a}}_{1}\mathbit{A}+{\mathit{a}}_{2}{\mathbit{A}}^{2}$, where $\mathbit{A}$ is a 2-by-2 matrix.

Create the matrix $\mathbit{A}$ and the coefficients ${\mathit{a}}_{0}$, ${\mathit{a}}_{1}$, and ${\mathit{a}}_{2}$ as symbolic matrix variables. Create the matrix polynomial as a symbolic matrix function `f` with $\mathbit{A}$, ${\mathit{a}}_{0}$, ${\mathit{a}}_{1}$, and ${\mathit{a}}_{2}$ as its parameters.

```syms A [2 2] matrix syms a0 a1 a2 [1 1] matrix syms f(A,a0,a1,a2) [2 2] matrix keepargs f(A,a0,a1,a2) = a0*eye(2) + a1*A + a2*A^2```
`f(A, a0, a1, a2) = ${a}_{0} {\mathrm{I}}_{2}+{a}_{1} A+{a}_{2} {A}^{2}$`

Find the inverse of `f` using `inv`. The result is a symbolic matrix function of type `symfunmatrix`.

`fInv = inv(f)`
`fInv(A, a0, a1, a2) = ${\left({a}_{0} {\mathrm{I}}_{2}+{a}_{1} A+{a}_{2} {A}^{2}\right)}^{-1}$`

Evaluate the inverse for the matrix value $\mathbit{A}=\left[2\text{\hspace{0.17em}}\text{\hspace{0.17em}}-1;-1\text{\hspace{0.17em}}\text{\hspace{0.17em}}2\right]$ and the coefficient values ${\mathit{a}}_{0}=-1$, ${\mathit{a}}_{1}=2$, and ${\mathit{a}}_{2}=3$. The result is a symbolic matrix variable of type `symmatrix`.

```Aval = [2 -1; -1 2]; fEval = fInv(Aval,-1,2,3)```
```fEval =  ```

Convert the result from the `symmatrix` data type to the `sym` data type using `symmatrix2sym`. The result is a matrix of symbolic numbers.

`symmatrix2sym(fEval)`
```ans =  $\left(\begin{array}{cc}\frac{9}{64}& \frac{7}{64}\\ \frac{7}{64}& \frac{9}{64}\end{array}\right)$```

## Input Arguments

collapse all

Input matrix, specified as a square numeric matrix, square matrix of symbolic scalar variables, square symbolic matrix variable, square symbolic matrix function, or symbolic expression with square size.

Data Types: `single` | `double` | `sym` | `symmatrix` | `symfunmatrix`

## Tips

• Matrix computations involving many symbolic variables can be slow. To increase the computational speed, reduce the number of symbolic variables by substituting the given values for some variables.

## Version History

Introduced before R2006a

expand all