Find a Guide

Inverse and Transposing Matrices in MATLAB

Introduction

When working with matrices in MATLAB, there are two important mathematical features that should be talked about: how to take the inverse of a matrix and how to transpose a matrix.

Inverse of Matrix

To take the inverse of a matrix in MATLAB, there are two different ways this can be done.

matlab

mat = [   1 0 2
              -1 5 0
               0 3 -9 ];

inv(mat)
% output: [ 0.8824   -0.1176    0.1961
%                  0.1765    0.1765    0.0392
%                  0.0588    0.0588   -0.0980 ]

mat^(-1)
% output: [ 0.8824   -0.1176    0.1961
%                  0.1765    0.1765    0.0392
%                  0.0588    0.0588   -0.0980 ]

Either by using the built-in function 'inv()' or by taking a matrix to the power of -1, we can get the inverse of a matrix.

Transpose Matrix

To take the transpose of a real matrix, there are two ways this can be done. Either by using an apostrophe, or a dot followed by an apostrophe.

matlab

mat2 = [ 1 2
               3 4 ];

mat2'
% output: [ 1 3
%                2 4 ]

mat2.'
% output: [ 1 3
%                2 4 ]

For real matrices, this does the same thing, however, for matrices with imaginary values in one or more spots, these two methods make a big difference. Let's see how:

matlab

mat3 = [ 2       -1+1j
                7-2j -1-1j ];

mat3'
% output: [ 2       7+2j
%                -1-1j -1+1j ]

mat3.'
% output: [ 2       7-2j
%                -1+1j -1-1j ]

When transposing matrices with imaginary value, using the apostrophe would take what is called the Hermitian. This essentially takes the transpose of a matrix and takes the complex conjugate of the matrix (changes the sign of the imaginary components). To take the transpose of matrices without taking the complex conjugate, we can use a dot followed by an apostophe (.').

Find a Guide