# det

Determinant of symbolic matrix

## Syntax

``B = det(A)``
``B = det(A,'Algorithm','minor-expansion')``
``B = det(M)``

## Description

example

````B = det(A)` returns the determinant of the square matrix of symbolic numbers, scalar variables, or functions `A`.```

example

````B = det(A,'Algorithm','minor-expansion')` uses the minor expansion algorithm to evaluate the determinant of `A`.```

example

````B = det(M)` returns the determinant of the square symbolic matrix variable or matrix function `M`.```

## Examples

collapse all

Compute the determinant of a matrix that contains symbolic scalar variables.

```syms a b c d A = [a b; c d]; B = det(A)```
`B = $a d-b c$`

Compute the determinant of a matrix that contains symbolic numbers.

```A = sym([2/3 1/3; 1 1]); B = det(A)```
```B =  $\frac{1}{3}$```

Create a symbolic matrix that contains polynomial entries.

```syms a x A = [1, a*x^2+x, x; 0, a*x, 2; 3*x+2, a*x^2-1, 0]```
```A =  $\left(\begin{array}{ccc}1& a {x}^{2}+x& x\\ 0& a x& 2\\ 3 x+2& a {x}^{2}-1& 0\end{array}\right)$```

Compute the determinant of the matrix using minor expansion.

`B = det(A,'Algorithm','minor-expansion')`
`B = $3 a {x}^{3}+6 {x}^{2}+4 x+2$`

Compute the determinant of a 4-by-4 block matrix

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

where $A$, $B$, and $C$ 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 C [2 2] matrix Z = symmatrix(zeros(2))```
`Z = ${\mathrm{0}}_{2,2}$`
`M = [A Z; C B]`
```M =  $\left(\begin{array}{c}\begin{array}{cc}A& {\mathrm{0}}_{2,2}\end{array}\\ \begin{array}{cc}C& B\end{array}\end{array}\right)$```

Find the determinant of the matrix $M$.

`det(M)`
```ans =  $\mathrm{det}\left(\begin{array}{c}\begin{array}{cc}A& {\mathrm{0}}_{2,2}\end{array}\\ \begin{array}{cc}C& B\end{array}\end{array}\right)$```

Convert the result from symbolic matrix variables to symbolic scalar variables using `symmatrix2sym`.

`D1 = simplify(symmatrix2sym(det(M)))`
`D1 = $\left({A}_{1,1} {A}_{2,2}-{A}_{1,2} {A}_{2,1}\right) \left({B}_{1,1} {B}_{2,2}-{B}_{1,2} {B}_{2,1}\right)$`

Check if the determinant of matrix $M$ is equal to the determinant of $A$ times the determinant of $B$.

`D2 = symmatrix2sym(det(A)*det(B))`
`D2 = $\left({A}_{1,1} {A}_{2,2}-{A}_{1,2} {A}_{2,1}\right) \left({B}_{1,1} {B}_{2,2}-{B}_{1,2} {B}_{2,1}\right)$`
`isequal(D1,D2)`
```ans = logical 1 ```

Compute the determinant 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 determinant of `f` using `det`. The result is a symbolic matrix function of type `symfunmatrix`.

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

Evaluate the determinant for the matrix value $\mathbit{A}=\left[1\text{\hspace{0.17em}}\text{\hspace{0.17em}}-2;-3\text{\hspace{0.17em}}\text{\hspace{0.17em}}4\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 = [1 -2; -3 4]; fEval = fDet(Aval,-1,2,3)```
```fEval =  ```

Convert the evaluated determinant from a symbolic matrix variable to a symbolic number using `symmatrix2sym`. The evaluated determinant for the given values is $-128$.

`symmatrix2sym(fEval)`
`ans = $-128$`

## Input Arguments

collapse all

Input matrix, specified as a square matrix of symbolic numbers, square matrix of symbolic scalar variables, or square matrix of symbolic functions.

Data Types: `single` | `double` | `sym` | `symfun`

Input matrix, specified as a square symbolic matrix variable or square symbolic matrix function.

Data Types: `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.

• The minor expansion method is generally useful to evaluate the determinant of a matrix that contains many symbolic scalar variables. This method is often suited to matrices that contain polynomial entries with multivariate coefficients.

 Khovanova, T. and Z. Scully. "Efficient Calculation of Determinants of Symbolic Matrices with Many Variables." arXiv preprint arXiv:1304.4691 (2013).