Implementation of Cayley-Hamilton’s Theorem in MATLAB

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 relationship

[Tex]|A-λI| = 0[/Tex] where 'λ' is some real constant and 'I' is the identity matrix of order, the same as that of A's order.

Expanding the above Relation we get the: 

λ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’, we have:

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

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 | w3wiki") 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: