# Maths - Eigenvectors and Eigenvalues of 2×2 Matrix

The method for symbolic computation of eigenvectors and eigenvalues involves first finding the eigenvalues from the characteristic polynomial:

det(M - λ I) = 0

where, in this case for two dimensional matrix M =

 m00 m01 m10 m11

which gives the characteristic equation:

(m00 - λ)(m11 - λ) - m01 m10 = 0

expanding out gives:

λ² - (m00 + m11)λ + (m00 m11 - m01 m10) = 0

where:

• (m00 + m11) = trace
• (m00 m11 - m01 m10) = determinant

λ = (m00 + m11)/2 ± (√(4*m01*m10 + (m00 - m11)²))/2

We can then substitute these into

 m00 - λ m01 m10 m11 - λ
=
 0 0

which is equivalent to solving 2 simultaneous equations.

### Special Cases

If the matrix is symmetrical around the leading diagonal:

m01=m10

then:

λ = (m00 + m11)/2 ± (√(2*m01)² + (m00 - m11)²))/2

## Code

Here is a Java function to return the eigenvalues:

```/**
code to return eigenvalues of a 2x2 matrix
result we be returned in resultReal[0],resultImaginary[0],resultReal[1] and resultImaginary[1]
expects arrays to be setup before being called, like this:
double[] resultReal= new double[2];
double[] resultImaginary = new double[2];
*/
public void eigenValue(double[][] m, double[] resultReal , double[] resultImaginary) {
return;
}
```

## Example - 2D Rotation Matrix

A 2D rotation matrix can be written:

 cos(θ) -sin(θ) sin(θ) cos(θ)

So we can work out the eigen values as follows:

λ = (m00 + m11)/2 ± (√(4*m01*m10 + (m00 - m11)²))/2

λ = (cos(θ) + cos(θ))/2 ± (√(-4*sin(θ)*sin(θ) + (cos(θ) - cos(θ))²))/2

λ = cos(θ) ± (√(-4*sin(θ)*sin(θ)))/2

λ = cos(θ) ± i sin(θ) = e±iθ

substitute these into [M] {v} = λ {v}

 cos(θ) - λ -sin(θ) sin(θ) cos(θ) - λ
 v1 v2
=
 0 0

let λ = cos(θ) + i sin(θ) gives:

 - i sin(θ) -sin(θ) sin(θ) - i sin(θ)
 v1 v2
=
 0 0

so,

 v1 v2
=
 0 0

## Program

There are a number of open source programs that can calculate eigenvalues and eigenvectors. I have used Axiom, how to install Axiom here.

To get a numeric solution for a given matrix, we can use eigenvalues(m) and eigenvectors(m) as shown here:

I have put user input in red:

 `(1) -> m := matrix[[1,4],[2,5]]` ` +1 4+ (1) | | +2 5+ Type: Matrix Integer(2) -> ev := eigenvalues(m)` ``` 2 (2) [%A | %A - 6%A - 3]Type: List Union(Fraction Polynomial Integer,SuchThat(Symbol, Polynomial Integer)) (3) -> eigenvectors(m)``` ``` +%B - 5+ 2 |------| (3) [[eigval= (%B | %B - 6%B - 3),eigmult= 1,eigvec= [| 2 |]]] | | + 1 + Type: List Record(eigval: Union(Fraction Polynomial Integer,SuchThat(Symbol, Polynomial Integer)),eigmult: NonNegativeInteger,eigvec: List Matrix Fraction Polynomial Integer)(4) -> ```

Or we can find a general formula for a given matrix as shown here:

 `(1) -> msymb := matrix[[a,b],[c,d]] ` ``` +a b+ (1) | | +c d+ Type: Matrix Polynomial Integer(2) -> ``` `(2) -> evsymb := eigenvalues(msymb)` ``` 2 (2) [%A | (a - %A)d - b c - %A a + %A ]Type: List Union(Fraction Polynomial Integer, SuchThat(Symbol,Polynomial Integer)) (3) -> eigenvectors(msymb)``` ``` (3) [ 2 [eigval= (%B | (a - %B)d - b c - %B a + %B ), eigmult= 1, +- d + %B+ |--------| eigvec= [| c |]] | | + 1 + ]Type: List Record(eigval: Union(Fraction Polynomial Integer, SuchThat(Symbol,Polynomial Integer)),eigmult: NonNegativeInteger,eigvec: List Matrix Fraction Polynomial Integer)(4) -> ```