This lecture considered a change of basis for vectors and matrices (tensors)
A vector $\boldsymbol{a}$ is represented in terms of its components $a_{i}$with respect to a given basis, e.g.
$$ \boldsymbol{a} = a_{1} \boldsymbol{e}_{1} + a_{2} \boldsymbol{e}_{2} + a_{3} \boldsymbol{e}_{3} $$(in old-fashioned notation for the canonical basis $\boldsymbol{i}$, $\boldsymbol{j}$, $\boldsymbol{k}$ is used). Using a suitable basis can sometimes simply construction and/or manipulations, but the 'physical' meaning to the vector is unchanged. With respect to a new basis, say ${\boldsymbol{e}^{\prime}_{i}}$, the coefficients will change:
$$ \boldsymbol{a} = a^{\prime}_{1} \boldsymbol{e}^{\prime}_{1} + a^{\prime}_{2} \boldsymbol{e}^{\prime}_{2} + a^{\prime}_{3} \boldsymbol{e}^{\prime}_{3} $$In an attempt at simplicity, in the notes we drop the vector basis and consider the somewhat imprecise concept of rotating the coordinate system.
When considering the rotation of vectors, we looked at the rotation of the unit coordinate vectors, $[1, 0, 0]$, $[0, 1, 0]$ and $[0, 0, 1]$ to $\boldsymbol{q}_{1}$, $\boldsymbol{q}_{2}$ and $\boldsymbol{q}_{3}$, respectively. From this, the matrix $\boldsymbol{Q}$ can be formed:
$$ \boldsymbol{Q} = \begin{bmatrix} \uparrow & \uparrow & \uparrow \\ \boldsymbol{q}_{1} & \boldsymbol{q}_{2} & \boldsymbol{q}_{3} \\ \downarrow & \downarrow & \downarrow \end{bmatrix} $$When changing the coordinate system, the vector remains fixed but we rotate the basis. As a consequence, its components will change. If the basis $[1, 0, 0]$, $[0, 1, 0]$ and $[0, 0, 1]$ is rotated to $\boldsymbol{q}_{1}$, $\boldsymbol{q}_{2}$ and $\boldsymbol{q}_{3}$, respectively, the coefficients of a vector $\boldsymbol{a}$ in the rotated coordinate system are $\boldsymbol{a}^{\prime}$
$$ \boldsymbol{a}^{\prime} = \boldsymbol{Q}^{T} \boldsymbol{a} = \boldsymbol{R} \boldsymbol{a} $$Matrices that operate on vectors with an associated basis are in fact tensors, and can also be rotated:
$$ \boldsymbol{A}^{\prime} = \boldsymbol{R} \boldsymbol{A} \boldsymbol{R}^{T} $$We illustrate now a transformation of an $n \times n$ matrix $\boldsymbol{A}$ that will make the matrix particularly simple. We first create a symmetric matrix $\boldsymbol{A}$ (it will be become clearer later why we consider a symmetric matrix).
In [1]:
# Import NumPy and seed random number generator to make generated matrices deterministic
import numpy as np
np.random.seed(1)
# Create a symmetric matrix with random entries
A = np.random.rand(4, 4)
A = A + A.T
print(A)
We need to create a rotation matrix $\boldsymbol{R}$, which we will do via computation of the eigenvectors (eigenvectors are covered in the next lecture). The details are not so important here; we just need an orthogonal matrix. Computing the eigenvectors of $\boldsymbol{A}$ and checking that the eigenvectors are orthonormal:
In [2]:
# Compute eigenvectors to generate a set of orthonormal vector
evalues, evectors = np.linalg.eig(A)
# Verify that eigenvectors R[i] are orthogonal (see Lecture 8 notebook)
import itertools
pairs = itertools.combinations_with_replacement(range(np.size(evectors, 0)), 2)
for p in pairs:
e0, e1 = p[0], p[1]
print("Dot product of eigenvectors vectors {}, {}: {}".format(e0, e1, evectors[:, e0].dot(evectors[:, e1])))
We have verified that the eigenvectors form an orthonormal set, and hence can be used to construct a rotation transformation matrix $\boldsymbol{R}$. For reasons that will become apparent later, we choose $\boldsymbol{R}$ to be a matrix whose rows are the eigenvectors of $\boldsymbol{A}$:
In [3]:
R = evectors.T
We now apply the transformation defined by $\boldsymbol{R}$ to $\boldsymbol{A}$:
In [4]:
Ap = (R).dot(A.dot(R.T))
print(Ap)
Note that the transformed matrix is diagonal. We will investigate this further in following lectures.
We can reverse the transformation by exploiting the fact that $\boldsymbol{R}$ is an orthogonal matrix:
In [5]:
print((R.T).dot(Ap.dot(R)))
which is the same as the original matrix.