Linear Transformations
This post is the first in a 3-part series on building geometric intuition about key concepts in linear algebra.
In [1]:
%matplotlib inline
import warnings
warnings.filterwarnings('ignore')
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns
%config InlineBackend.figure_format = 'retina'
from plot_helper import *
#
Dilation (stretch / shrink) ¶
$$ \begin{pmatrix} 3 & 0 \\ 0 & 1 \\ \end{pmatrix} \begin{pmatrix} 1 \\ 1 \\ \end{pmatrix} = \begin{pmatrix} 3 \\ 1 \\ \end{pmatrix} $$
In [3]:
M = np.array([[3, 0],[0, 1]])
x = np.array([1,1])
plot_linear_transformation(M, x, unit_vector=True, unit_circle=True)
#
Reflection around y-axis ¶
$$ \begin{pmatrix} -1 & 0 \\ 0 & 1 \\ \end{pmatrix} \begin{pmatrix} 1 \\ 1 \\ \end{pmatrix} = \begin{pmatrix} -1 \\ 1 \\ \end{pmatrix} $$
In [4]:
M = np.array([[-1, 0],[0, 1]])
plot_linear_transformation(M, x, unit_vector=True, unit_circle=True)
#
Projection ¶
$$ \begin{pmatrix} 3 & 0 \\ 0 & 0 \\ \end{pmatrix} \begin{pmatrix} 1 \\ 1 \\ \end{pmatrix} = \begin{pmatrix} 3 \\ 0 \\ \end{pmatrix} $$
In [5]:
M = np.array([[3, 0],[0, 0]])
plot_linear_transformation(M, x, unit_vector=True, unit_circle=True)
#
In [6]:
np.linalg.matrix_rank(M)
Out[6]:
Rotation ¶
$$ \begin{pmatrix} 0 & -1 \\ 1 & 0 \\ \end{pmatrix} \begin{pmatrix} 1 \\ 1 \\ \end{pmatrix} = \begin{pmatrix} -1 \\ 1 \\ \end{pmatrix} $$
In [8]:
M = np.array([[0, -1],[1, 0]])
plot_linear_transformation(M, x, unit_vector=True, unit_circle=True)
#
Can you spot the difference between the above picture and the reflection around y-axis? ¶
Shear in the x-direction ¶
$$ \begin{pmatrix} 1 & 1 \\ 0 & 1 \\ \end{pmatrix} \begin{pmatrix} 1 \\ 1 \\ \end{pmatrix} = \begin{pmatrix} 2 \\ 1 \\ \end{pmatrix} $$
In [9]:
M = np.array([[1, 1],[0, 1]])
plot_linear_transformation(M, x, unit_vector=True, unit_circle=True)
#
Shear in the y-direction ¶
$$ \begin{pmatrix} 1 & 0 \\ 1 & 1 \\ \end{pmatrix} \begin{pmatrix} 1 \\ 1 \\ \end{pmatrix} = \begin{pmatrix} 1 \\ 2 \\ \end{pmatrix} $$
In [10]:
M = np.array([[1, 0],[1, 1]])
plot_linear_transformation(M, x, unit_vector=True, unit_circle=True)
#