Inverse matrix in Matlab
To calculate the inverse of a square matrix in Matlab, use the inv() function.
inv(m),
where m
is a matrix array.
How it Works
First, define a square matrix and assign it to a variable, here called M
:
M = [1,2;3,4]
In this example, M
is a 2x2 matrix:
$$ M= \begin{pmatrix} 1 & 2 \\
3 & 4 \end{pmatrix} $$
Next, compute the inverse matrix using the inv() function and store the result in the variable M2
:
M2 = inv(M)
The content in M2
is the inverse of M
, with decimal-format elements:
$$ \begin{pmatrix} -2.00000 & 1.00000 \\
1.50000 & -0.50000 \end{pmatrix} $$
This can also be represented as $$ M2 = \begin{pmatrix} -2 & 1 \\
1.5 & -0.5 \end{pmatrix} $$