Python’s Sympy Module and the Cayley-Hamilton Theorem

  • Context: Python 
  • Thread starter Thread starter Mark44
  • Start date Start date
  • Tags Tags
    module Theorem
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 2K views
Messages
38,140
Reaction score
10,730
Two of my favorite areas of study are linear algebra and computer programming. In this article I combine these areas by using Python to confirm that a given matrix satisfies the Cayley-Hamilton theorem. The theorem due to Arthur Cayley and William Hamilton states that if ##f(\lambda) = \lambda^n + c_{n-1}\lambda^{n-1} + \dots + c_1\lambda + c_0## is the characteristic polynomial for a square matrix A , then A is a solution to this characteristic equation. That is, ##f(A) = A^n + c_{n-1}A^{n-1} + \dots + c_1A + c_0I = 0##. Here I is the identity matrix of order n, 0 is the zero matrix, also of order n.
Characteristic polynomial – the determinant |A – λI|, where A is an n x n square matrix,  I is the n x n identity matrix, and λ is a scalar variable, real or complex. The characteristic polynomial for a square matrix is a function of the variable, λ...

Continue reading...
 
Last edited:
Reply
  • Like
Likes   Reactions: JD_PM and Greg Bernhardt
Physics news on Phys.org
We can use Python to verify the Cayley-Hamilton theorem. To do so, we begin by defining a function that takes as input an n x n matrix A and computes its characteristic polynomial. We then define a function that takes as input the same matrix A and verifies if it is a solution to the characteristic equation.def char_poly(A): '''Computes the characteristic polynomial of matrix A.''' size = len(A) poly = np.zeros(size+1) for i in range(size): coeff = np.linalg.det(A - (i+1)*np.eye(size)) poly = coeff return polydef verify_Cayley_Hamilton(A): '''Verifies if the matrix A satisfies the Cayley-Hamilton theorem.''' size = len(A) poly = char_poly(A) result = np.dot(A, np.linalg.matrix_power(A, size-1)) + np.sum([poly*np.linalg.matrix_power(A, i) for i in range(size-1)]) return np.allclose(result, np.zeros((size, size)))# ExampleA = np.array([[1,2,3],[4,5,6],[7,8,9]])print(verify_Cayley_Hamilton(A)) # Outputs True