Implementation of Cayley-Hamilton’s Theorem in MATLAB
Last Updated :
07 Apr, 2022
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 :
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
clear all
clc
disp( "Cayley-Hamilton’s theorem in MATLAB | GeeksforGeeks" )
A = input( "Enter a matrix A : " )
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
Share your thoughts in the comments
Please Login to comment...