Eigenvalues of a matrix in Octave
In this lesson I'll explain how to calculate the eigenvalues of a matrix in Matlab.
What are the eigenvalues? Eigenvalues are the solutions of the characteristic equation associated with a square matrix.
I'll give you a practical example
Create a 2x2 square matrix and assign it to variable M
>> M = [ 1 2 ; 0 3 ]
M =
1 2
0 3
Type eig(M) on the command line to calculate the eigenvalues of the square matrix M.
>> eig(M)
ans =
1
3
The eigenvalues of the square matrix M are scalars 1 and 3.
Verify. Let's check to see if the result is right. The square matrix used in the example is the following M $$ M = \begin{pmatrix} 1 & 2 \\ 0 & 3 \end{pmatrix} $$ The characteristic polynomial PM(λ) of the matrix M is defined by the determinant of M-λ · Id$$ P_M(λ) = \det(M-\lambda \cdot Id) $$ where M is the square matrix, Id is an identity matrix of the same order and λ is an unknown variable. $$ P_M(λ) = \det [ \begin{pmatrix} 1 & 2 \\ 0 & 3 \end{pmatrix} -\lambda \cdot \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix} ] $$ $$ P_M(λ) = \det [ \begin{pmatrix} 1 & 2 \\ 0 & 3 \end{pmatrix} - \begin{pmatrix} \lambda & 0 \\ 0 & \lambda \end{pmatrix} ] $$ $$ P_M(λ) = \det \begin{pmatrix} 1- \lambda & 2 \\ 0 & 3-\lambda \end{pmatrix} $$ $$ P_M(λ) = (1-\lambda) \cdot (3-\lambda)$$ $$ P_M(λ) = 3 - \lambda - 3 \lambda + \lambda^2 $$ $$ P_M(λ) = \lambda^2 - 4 \lambda + 3 $$ The characteristic equation of the matrix is the characteristic polynomial P (x) = 0 set equal to zero $$ P_M(λ) = 0 $$ $$ \lambda^2 - 4 \lambda + 3 = 0 $$ The eigenvalues are the solutions of the characteristic equation. In this case the characteristic equation is a 2nd degree equation.$$ \lambda = \frac{-b \pm \sqrt{b^2-4ac}}{2a} $$ $$ \lambda = \frac{-(-4) \pm \sqrt{(-4)^2-4 \cdot 1 \cdot 3}}{2 \cdot 1} $$ $$ \lambda = \frac{4 \pm \sqrt{16-12}}{2} $$ $$ \lambda = \frac{4 \pm \sqrt{4}}{2} $$ $$ \lambda = \frac{4 \pm 2}{2} = \begin{cases} \lambda_1 = \frac{4-2}{2} = 1 \\ \\ \lambda_2 = \frac{4+2}{2} = 3 \end{cases} $$ In conclusion, the eigenvalues of the matrix M are the scalars 1 and 3. The result is correct.