# pinv

Moore-Penrose inverse (pseudoinverse) of symbolic matrix

## Syntax

``X = pinv(A)``

## Description

example

````X = pinv(A)` returns the pseudoinverse of `A`. Pseudoinverse is also called the Moore-Penrose inverse.```

## Examples

### Compute Pseudoinverse of Matrix

Compute the pseudoinverse of this matrix. Because these numbers are not symbolic objects, you get floating-point results.

```A = [1 1i 3; 1 3 2]; X = pinv(A)```
```X = 0.0729 + 0.0312i 0.0417 - 0.0312i -0.2187 - 0.0521i 0.3125 + 0.0729i 0.2917 + 0.0625i 0.0104 - 0.0938i```

Now, convert this matrix to a symbolic object, and compute the pseudoinverse.

```A = sym([1 1i 3; 1 3 2]); X = pinv(A)```
```X = [ 7/96 + 1i/32, 1/24 - 1i/32] [ - 7/32 - 5i/96, 5/16 + 7i/96] [ 7/24 + 1i/16, 1/96 - 3i/32]```

Check that `A*X*A = A` and `X*A*X = X`.

`isAlways(A*X*A == A)`
```ans = 2×3 logical array 1 1 1 1 1 1```
`isAlways(X*A*X == X)`
```ans = 3×2 logical array 1 1 1 1 1 1```

Now, verify that `A*X` and `X*A` are Hermitian matrices.

`isAlways(A*X == (A*X)')`
```ans = 2×2 logical array 1 1 1 1```
`isAlways(X*A == (X*A)')`
```ans = 3×3 logical array 1 1 1 1 1 1 1 1 1```

### Compute Pseudoinverse of Matrix

Compute the pseudoinverse of this matrix.

```syms a A = [1 a; -a 1]; X = pinv(A)```
```X = [ (a*conj(a) + 1)/(a^2*conj(a)^2 + a^2 + conj(a)^2 + 1) -... (conj(a)*(a - conj(a)))/(a^2*conj(a)^2 + a^2 + conj(a)^2 + 1), - (a - conj(a))/(a^2*conj(a)^2 + a^2 + conj(a)^2 + 1) -... (conj(a)*(a*conj(a) + 1))/(a^2*conj(a)^2 + a^2 + conj(a)^2 + 1)] [ (a - conj(a))/(a^2*conj(a)^2 + a^2 + conj(a)^2 + 1) +... (conj(a)*(a*conj(a) + 1))/(a^2*conj(a)^2 + a^2 + conj(a)^2 + 1), (a*conj(a) + 1)/(a^2*conj(a)^2 + a^2 + conj(a)^2 + 1) -... (conj(a)*(a - conj(a)))/(a^2*conj(a)^2 + a^2 + conj(a)^2 + 1)]```

Now, compute the pseudoinverse of `A` assuming that `a` is real.

```assume(a,'real') A = [1 a; -a 1]; X = pinv(A)```
```X = [ 1/(a^2 + 1), -a/(a^2 + 1)] [ a/(a^2 + 1), 1/(a^2 + 1)]```

For further computations, remove the assumption on `a` by recreating it using `syms`.

`syms a`

## Input Arguments

collapse all

Input, specified as a symbolic matrix.

## Output Arguments

collapse all

Pseudoinverse of matrix, returned as a symbolic matrix, such that ```A*X*A = A``` and `X*A*X = X`.

collapse all

### Moore-Penrose Pseudoinverse

The pseudoinverse of an m-by-n matrix `A` is an n-by-m matrix `X`, such that `A*X*A = A` and ```X*A*X = X```. The matrices `A*X` and `X*A` must be Hermitian.

## Tips

• Calling `pinv` for numeric arguments that are not symbolic objects invokes the MATLAB® `pinv` function.

• For an invertible matrix `A`, the Moore-Penrose inverse `X` of `A` coincides with the inverse of `A`.