- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Implementation of Cayley-Hamilton's Theorem in MATLAB
In linear algebra, there is a fundamental theorem caled Cayley-Hamilton’s Theorem that is used to establish a relation between a square matrix and its characteristic equation. Read this article to learn the implementation of the Cayley-Hamilton’s theorem in MATLAB programming. Let's start with an overview of Cayley-Hamilton’s theorem.
What is Cayley-Hamilton’s Theorem?
In linear algebra, the Cayley-Hamilton’s theorem is a fundamental theorem that is used to establish a relationship between a square matrix and its characteristic equation. In other words, according Cayley-Hamilton’s theorem, a square matrix must satisfy its own characteristic equation.
Explanation
Consider a square matrix A of the order of "n". If $\mathrm{p(\lambda)}$ is the characteristic polynomial of the matrix A, then it is given by,
$$\mathrm{p(\lambda) \: = \: \lvert \lambda I \: − \: A \rvert}$$
Where,
"I" is the identity matrix of the order of "n".
$\mathrm{"\lambda"}$ is a real constant.
The roots of this polynomial $\mathrm{p(\lambda)}$ are called the "eigenvalues" of the square matrix A.
As per Cayley-Hamilton’s theorem, if the polynomial $\mathrm{p(\lambda)}$ is the characteristic polynomial of a square matrix "A". Then, if we substitute $\mathrm{\lambda \: = \: A}$ in $\mathrm{p(\lambda)}$, it gives a zero matrix i.e.,
$$\mathrm{p(A) \: = \: 0}$$
Therefore, if we evaluate the characteristic polynomial of a square matrix A at the matrix A itself, then it results in a zero matrix. Hence, the Cayley-Hamilton’s theorem satisfies its own characteristic polynomial.
The Cayley-Hamilton’s theorem plays a vital role in various field of engineering like control theory, physics, signal processing, and more. This is all about basics of Cayley-Hamilton’s theorem. Let us now learn its implementation in MATLAB.
Implementation of Cayley-Hamilton’s Theorem in MATLAB
We can implement the Cayley-Hamilton’s theorem in MATLAB. The two simplest methods of implementing the Cayley-Hamilton’s theorem are explained below.
Method (1) – Cayley-Hamilton’s Theorem by Defining a Function
function CH(A) % Check whether the input matrix is a square matrix [m, n] = size(A); if m ~= n error('Input matrix is not a square matrix.'); end % Defining characteristic polynomial of input square matrix p = poly(A); % Cayley-Hamilton theorem calculation r = polyvalm(p, A); % Display the result disp('Cayley-Hamilton Theorem:'); disp(r); % Verify the Cayley-Hamilton Theorem if isequal(round(r), zeros(size(A))) disp('Cayley-Hamilton theorem is verified.'); else disp('Cayley-Hamilton theorem verification failed.'); end end
Save this function in the current workspace in your MATLAB environment. Then, open the MATLAB command window, and call the "CH" function to compute the Caley-Hamilton’s theorem.
Example 1
% Create a square matrix A = [10, 20; 30, 40]; % Calculate Cayley-Hamilton’s theorem CH(A);
Output
It will produce the following output −
Cayley-Hamilton Theorem: 0 0 0 0 Cayley-Hamilton theorem is verified.
Example 2
% Create a square matrix A = [10, 20 30; 30, 40, 50]; % Calculate Cayley-Hamilton’s theorem CH(A);
Output
It will produce the following output −
Error using CH Input matrix is not a square matrix.
Let us now discuss another method of implementing the Cayley-Hamilton’s theorem in MATLAB.
Method (2) – Cayley-Hamilton Theorem Calculating using "for" Loop
The following example program demonstrates the implementation of Cayley-Hamilton’s theorem in MATLAB.
Example 3
% MATLAB program to Implement Cayley-Hamilton’s theorem % Input a square matrix A = [10, 20; 30, 40]; % Check if the input matrix is a square matrix [m, n] = size(A); if m ~= n error('Input matrix is not a square matrix.'); end % Store the size of the input matrix in a variable mat_size = size(A); % Characteristic polynomial calculation p = poly(A); % Create a zero matrix of the same size as A r = zeros(mat_size); % Calculate Cayley-Hamilton theorem using a loop for i = 1 : (mat_size(1) + 1) r = r + p(i) * (A^(mat_size(1)+1 - i)); end % Display the result disp("Cayley-Hamilton’s Theorem:"); disp(round(r)); % Verify Cayley-Hamilton theorem if isequal(round(r), zeros(mat_size)) disp("Cayley-Hamilton theorem is verified.") else disp("Cayley-Hamilton theorem verification is failed.") end
Output
It will produce the following output −
Cayley-Hamilton’s Theorem: 0 0 0 0 Cayley-Hamilton theorem is verified.
If we replace the input matrix "A" from a non-square matrix given below −
A = [10, 20, 30; 30, 40, 50];
Then, the output will be −
Input matrix is not a square matrix.
Conclusion
In conclusion, the Cayley-Hamilton’s theorem is a powerful result in linear algebra that gives a relationship between a square matrix and its characteristic equation or polynomial. We can implement the Cayley-Hamilton’s theorem in MATLAB. In this article, I explained the two most simple methods of implementing the Cayley-Hamilton’s theorem in MATLAB with the help of examples. You can try these MATLAB codes with different square matrices to see the results.
To Continue Learning Please Login
Login with Google