Open In App

Implementation of Cayley-Hamilton’s Theorem in MATLAB

Last Updated : 07 Apr, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

According to Linear Algebra, every square matrix satisfies its own characteristic equation. Consider a Square Matrix ‘A’ with order ‘n’, then its Characteristic equation is given by the Relation :

|A-λI| = 0 
where 'λ' is some Real Constant and 'I' is the Identity
Matrix of Order same as that of A's Order.

Expanding the above Relation we get: 

λn + C1λn-1 + C2λn-2 + . . . + CnIn = 0 (
Another form of Characteristic equation)
where C1, C2, . . . , Cn are Real Constants.

According to Cayley-Hamilton’s theorem, The above equation is satisfied by ‘A’, Hence we have:

An + C1An-1 + C2An-2 + . . . + CnIn = 0 

Different Methods that are used in the following code are:

  • input(text): This Method Displays the text written inside it and waits for the user to input a value and press the Return key.
  • size(A):  This method returns a row vector whose elements are the lengths of the corresponding dimensions of ‘A’.
  • poly(A): This method returns the n+1 coefficients of the characteristic polynomial of the square matrix ‘A’.
  • zeroes(size): This method returns an array of zeros with a size vector equal to that of ‘size’.

Example:

Matlab

% MATLAB code for Implementation of Cayley-Hamilton’s theorem
clear all     
clc           
disp("Cayley-Hamilton’s theorem in MATLAB | GeeksforGeeks")
A = input("Enter a matrix A : ")
 
% DimA(1) = no. of Columns & DimA(2) = no. of Rows
DimA = size(A)
charp = poly(A)
P = zeros(DimA);
for i = 1:(DimA(1)+1)
    P = P + charp(i)*(A^(DimA(1)+1-i));
end
disp("Result of the Characteristic equation after substituting the Matrix itself = ")
disp(round(P))
if round(P)==0
    disp("Therefore, Caylay-Hamilton theorem is verified")
end

                    

Output:

 


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads