Finding Inverse of a Square Matrix using Cayley Hamilton Theorem in MATLAB


Let us start this tutorial with a brief discussion on "what is inverse of a square matrix" and "the significance of Cayley Hamilton theorem".

What is Inverse of Square Matrix?

In linear algebra, there is a fundamental concept called the inverse of a square matrix. Consider a square matrix ‘A’, then there will another square matrix ‘A-1’ such as A.A-1 = I, where I is an identity matrix. Here, A-1 is called the inverse of the square matrix A.

It is an important point to note that for a given square matrix the inverse can be found if and only if its determinant is non-zero. Such a matrix whose inverse can be calculated is also known as non-singular matrix, and a matrix whose inverse cannot be directly calculated is called a singular matrix.

The computation of inverse of a matrix plays a vital role in solving linear equations. It found applications in various fields such as engineering, computer graphics, simulations, etc.

Cayley Hamilton Theorem

Cayley Hamilton theorem is an elementary theorem in linear algebra which is used to find a relationship between a square matrix and its characteristic equation.

According to Cayley Hamilton theorem, any square matrix A satisfies its own characteristic equation, when it is calculated at the matrix itself.

Mathematically, if A is a square matrix and p(x) is its characteristic equation, then

p(A) = 0

Where, 0 is a zero matrix of the order of the matrix A.

The characteristic equation of the matrix A is given by,

$$\mathrm{p(x)=|A−xI|}$$

Here, "x" is a scalar variable and "I" is the identity matrix of the square matrix "A".

Steps to Find Inverse of Square Matrix using Cayley Hamilton Theorem

Th step-by-step process to find inverse of a square matrix using Cayley Hamilton theorem is explained here:

Step (1) – Firstly, calculate the characteristic equation of the given square matrix A, i.e.

$$\mathrm{p(x)=|A−xI|}$$

Where, "I" is the identity matrix of the square matrix A.

Step (2) – Obtain the matrix equation p(A) by replacing the variable "x" in the characteristic equation p(x) with square matrix A.

Step (3) – Obtain the zero matrix by solving the matrix equation p(A), i.e.,

p(A)=0

Where, 0 is a zero matrix of the same size as the square matrix A.

Step (4) – Write the matrix equation, i.e.

$$\mathrm{A.A^{-1}=I}$$

Where, A-1 is the inverse of the square matrix A.

Step (5) – Solve the matrix equation by performing matrix operations to obtain the inverse square matrix A-1.

This is all about steps involved in finding the inverse of a square matrix using the Cayley Hamilton theorem.

After getting an overview of inverse of a square matrix and Cayley Hamilton theorem, let us now discuss how to find the inverse of a square matrix using Cayley Hamilton theorem in MATLAB.

Find Inverse of Square Matrix using Cayley Hamilton Theorem in MATLAB

The following example programs in MATLAB demonstrates how to find the inverse of a square matrix using Cayley Hamilton theorem in MATAB.

Example

% MATLAB code to find Inverse of Sq. Matrix using Cayley Hamilton Theorem
% Create a sample square matrix
A = [1, 4, 2; 4, -5, 6; 3, 2, -9];

% Calculate coefficients of characteristic equation of matrix A
c = poly(A);

% Calculate number of coefficients in characteristic equation of matrix A
n = length(c);

% Initialize the inverse matrix
inv = c(1) * A^(n-2);

% Apply Cayley Hamilton theorem to calculate the inverse matrix A
for i = 2:n-1
    inv = inv + c(i) * A^(n-i-1);
end

% Verify that |A| = 0 or not
if round(c(n)) == 0
    disp('The square matrix A is a singular matrix and its inverse does not exist.')
else
    inv = inv / (-c(n));
    disp('The inverse of square matrix A:')
    disp(inv)
end

Output

The inverse of square matrix A:
   1.1186e-01   1.3559e-01   1.1525e-01
   1.8305e-01  -5.0847e-02   6.7797e-03
   7.7966e-02   3.3898e-02  -7.1186e-02

Example

Now, let us consider another example in which we will try to find the inverse of a singular square matrix and will see the result.

% MATLAB code to find Inverse of Sq. Matrix using Cayley Hamilton Theorem
% Create a sample square matrix
A = [1, 2, 3; 2, 4, 6; 3, 6, 9];

% Calculate coefficients of characteristic equation of matrix A
c = poly(A);

% Calculate number of coefficients in characteristic equation of matrix A
n = length(c);

% Initialize the inverse matrix
inv = c(1) * A^(n-2);

% Apply Cayley Hamilton theorem to calculate the inverse matrix A
for i = 2:n-1
    inv = inv + c(i) * A^(n-i-1);
end

% Verify that |A| = 0 or not
if round(c(n)) == 0
    disp('The square matrix A is a singular matrix and its inverse does not exist.')
else
    inv = inv / (-c(n));
    disp('The inverse of square matrix A:')
    disp(inv)
end

Output

The square matrix A is a singular matrix and its inverse does not exist.

Conclusion

In this tutorial, we discussed how to find the inverse of a square matrix using Cayley Hamilton theorem in MATLAB. For better understanding, we explained the theoretical concepts with appropriate examples.

Updated on: 07-Sep-2023

195 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements