One way to get the inverse of a matrix in MATLAB is to use the inv
function. The syntax is as follows:
main.m16 chars2 lines
where A
is the matrix you want to invert and inv_A
is the inverse of A
. Note that not all matrices are invertible, so you may need to check for singularity before attempting to calculate the inverse.
Here is an example:
main.m32 chars3 lines
This will give you a 2x2 matrix that is the inverse of A
.
main.m51 chars5 lines
You can verify that the matrix is the inverse by multiplying it with the original matrix and checking whether you get the identity matrix:
main.m60 chars7 lines
This confirms that inv_A
is the inverse of A
.
gistlibby LogSnag