Eigen Decomposition
My learning notes.
import matplotlib.pyplot as plt
import numpy as np
def plotVectors(vecs, cols, alpha=1):
"""
Plot set of vectors.
Parameters
----------
vecs : array-like
Coordinates of the vectors to plot. Each vectors is in an array. For
instance: [[1, 3], [2, 2]] can be used to plot 2 vectors.
cols : array-like
Colors of the vectors. For instance: ['red', 'blue'] will display the
first vector in red and the second in blue.
alpha : float
Opacity of vectors
Returns:
fig : instance of matplotlib.figure.Figure
The figure of the vectors
"""
plt.figure()
plt.axvline(x=0, color='#A9A9A9', zorder=0)
plt.axhline(y=0, color='#A9A9A9', zorder=0)
for i in range(len(vecs)):
x = np.concatenate([[0,0],vecs[i]])
plt.quiver([x[0]],
[x[1]],
[x[2]],
[x[3]],
angles='xy', scale_units='xy', scale=1, color=cols[i],
alpha=alpha)
u = np.array([1.5, 1])
A = np.array([
[1.2, 0.9],
[0, -0.4]
])
v = A @ u
plotVectors([u, v], cols=['red', 'blue'])
plt.xlim(-3, 3)
plt.ylim(-2, 2)
x = np.array([-0.4902, 0.8715])
y = A @ x
plotVectors([x, y], cols=['red', 'blue'])
plt.xlim(-1, 1)
plt.ylim(-0.4, 0.9)
The vector x has a special relationship with the matrix A: it is rescaled (with a negative value), but both the initial vector x and the transformed vector y are on the same line.
The vector x is an eigenvector of A. It is only scaled by a value, which is called an eigenvalue of the matrix A. An eigenvector of the matrix A is a vector that is contracted or elongated when transformed by the matrix. The eigenvalue is the scaling factor by which the vector is contracted or elongated.
\mA \vx = \lambda \vx