Calculating the determinant of a square matrix on Matlab

The det() function in MATLAB is used to calculate the determinant of a square matrix.

det(M)

Here, M is the matrix input, which is the function’s only parameter.

The det() function returns the determinant of M if it exists.

If the determinant does not exist, the function returns zero.

Note: Determinants can only be calculated for square matrices, which have an equal number of rows and columns. Learn more about determinants.

For example, let’s define a square matrix stored in M.

This matrix is of order 2.

M = [ 1 2 ; 3 4 ]

We can calculate the determinant by running det(M):

>> det(M)

The determinant of this matrix is -2.

ans = -2

Now, let’s define another matrix in M, this time a 3x3 matrix:

M = [ 1 2 3 ; 4 5 6 ; 7 8 9 ]

Using the det(M) function again, we calculate the determinant of this matrix.

det(M)

The result is a very small number:

ans = 6.6613e-16

This indicates that the determinant is effectively zero.

To make results clearer, I use the round() function to reduce small decimal values:

round(det(M), 5)

>> round(det(M), 5)

Now, the result is displayed as:

ans = 0

This confirms that matrix M has no non-zero determinant.

 
 

Please feel free to point out any errors or typos, or share suggestions to improve these notes. English isn't my first language, so if you notice any mistakes, let me know, and I'll be sure to fix them.

FacebookTwitterLinkedinLinkedin
knowledge base

Matrix in Matlab