Open Educational Resources

Linear Maps Between Vector Spaces: Examples and Problems

Examples and Problems

Example 1

Consider the symmetric matrix:

    \[ M=\left(\begin{matrix}1&1&0\\1&1&0\\0&0&1\end{matrix}\right) \]

Find M^T, the determinant of M, the kernel of M, the eigenvalues and eigenvectors of M, and find the coordinate transformation in which M is diagonal.


Since M is symmetric, therefore, M=M^T. The determinant of M can be obtained using the triple product of the row vectors. However, it is obvious that the first two vectors are linearly dependent (they are equal), therefore, \det{M}=0. The kernel of M can be obtained by finding the possible forms for the vector x that would satisfy the following equation:

    \[ Mx=0\Rightarrow\left(\begin{matrix}1&1&0\\1&1&0\\0&0&1\end{matrix}\right)\left(\begin{array}{c}x_1\\x_2\\x_3\end{array}\right)=0 \]


    \[ x_1+x_2=0\qquad x_1+x_2=0\qquad x_3=0 \]

By setting x_1=\alpha, we have x_2=-\alpha. Therefore, the kernel of M has the form:

    \[ \ker{M}=\left\{x=\left(\begin{array}{c}\alpha\\-\alpha\\0\end{array}\right)\bigg| \alpha\in\mathbb{R}\right\} \]

To find the eigenvalues of M we find the possible values for \lambda that would make the matrix M-\lambda I not invertible. In other words, we solve for \lambda that would satisfy:

    \[ \det{M-\lambda I}=0\Rightarrow \det\left(\begin{matrix}1-\lambda&1&0\\1&1-\lambda&0\\0&0&1-\lambda\end{matrix}\right)=0 \]


    \[ (1-\lambda)^3-(1-\lambda)=0\Rightarrow \lambda^3-3\lambda^2+2\lambda=0\Rightarrow \lambda (\lambda -2)(\lambda -1)=0 \]

Therefore, the possible three eigenvalues are: \lambda_1=0, \lambda_2=1, and \lambda_3=2. Note that since M is not invertible, \lambda=0 is automatically an eigenvalue for M.

The eigenvector ev_1 corresponding to the eigenvalue \lambda_1=0 can be found as follows:

    \[ M(ev_1)=0 (ev_1) \]

which is the same equation to find the vectors of the kernel. So, a normalized vector in the kernel would satisfy this equation. Therefore,

    \[ ev_1=\left(\begin{array}{c}\frac{1}{\sqrt{2}}\\\frac{-1}{\sqrt{2}}\\0\end{array}\right) \]

The eigenvector ev_2 corresponding to the eigenvalue \lambda_2=1 can be found as follows:

    \[ M(ev_2)=1 (ev_2) \Rightarrow \left(\begin{matrix}1&1&0\\1&1&0\\0&0&1\end{matrix}\right)\left(\begin{array}{c}{ev_2}_1\\{ev_2}_2\\{ev_2}_3\end{array}\right)=\left(\begin{array}{c}{ev_2}_1\\{ev_2}_2\\{ev_2}_3\end{array}\right) \]

Therefore, we have the following three equations:

    \[ {ev_2}_1+{ev_2}_2-{ev_2}_1=0\Rightarrow {ev_2}_2=0 \]

    \[ {ev_2}_1+{ev_2}_2-{ev_2}_2=0\Rightarrow {ev_2}_1=0 \]

    \[ {ev_2}_3={ev_2}_3 \]

Therefore, the normalized components of the second eigenvector are:

    \[ ev_2=\left(\begin{array}{c}0\\0\\1\end{array}\right) \]

Since M is symmetric, the third eigenvector has to be normal to the first and second eigenvectors. So, we can simply find a vector normal to ev_1 and ev_2. Or we can solve the equation:

    \[ M(ev_3)=2 (ev_3) \Rightarrow \left(\begin{matrix}1&1&0\\1&1&0\\0&0&1\end{matrix}\right)\left(\begin{array}{c}{ev_3}_1\\{ev_3}_2\\{ev_3}_3\end{array}\right)=2\left(\begin{array}{c}{ev_3}_1\\{ev_3}_2\\{ev_3}_3\end{array}\right) \]

Therefore, we have the following three equations:

    \[ {ev_3}_1+{ev_3}_2-2{ev_3}_1=0\Rightarrow {ev_3}_2-{ev_3}_1=0 \]

    \[ {ev_3}_1+{ev_3}_2-2{ev_3}_2=0\Rightarrow {ev_3}_1-{ev_3}_2=0 \]

    \[ {ev_3}_3=2{ev_3}_3 \Rightarrow {ev_3}_3=0 \]

Therefore, the normalized components of the third eigenvector are:

    \[ ev_3=\left(\begin{array}{c}\frac{1}{\sqrt{2}}\\\frac{1}{\sqrt{2}}\\0\end{array}\right) \]

The coordinate system in which the representation of the matrix M is diagonal is the coordinate system made of the three normalized eigenvectors of M. Setting B'=\{ev_3,-ev_1,ev_2\}, the coordinate transformation matrix Q has the form:

    \[ Q=\left(\begin{matrix}\frac{1}{\sqrt{2}}&\frac{1}{\sqrt{2}}&0\\\frac{-1}{\sqrt{2}}&\frac{1}{\sqrt{2}}&0\\0&0&1\end{matrix}\right) \]

Note that the order of the vectors in B' was chosen so that Q is a rotation matrix, i.e., the vectors of B' have to obey the right hand orientation. Therefore, the components of M' when using B' as the basis set are:

    \[ M'=QMQ^T=\left(\begin{matrix}2&0&0\\0&0&0\\0&0&1\end{matrix}\right) \]

Study the following Mathematica code and note the various functions used for matrix manipulations. Note that the function “NullSpace” can be used to find the vectors in the kernel. The actual kernel is the span of these vectors. Matrix multiplication is performed using the “.” character. Note also that the command “Eigensystem” in Mathematica can be used to produce the list of eigenvalues, followed by the list of eigenvectors. Study the code to see how the eigenvectors can be extracted, normalized, and then used to form the matrix Q.

View Mathematica Code

M = {{1, 1, 0}, {1, 1, 0}, {0, 0, 1}}; Mt = Transpose[M] Det[M] NullSpace[M] a = Eigensystem[M] ev1 = a[[2, 1]]/Norm[a[[2, 1]]] ev2 = a[[2, 3]]/Norm[a[[2, 3]]] ev3 = a[[2, 2]]/Norm[a[[2, 2]]] Q = {ev1, ev2, ev3}; Q // MatrixForm Mp = Q.M.Transpose[Q]; Mp // MatrixForm

View Python Numpy Code

import numpy as np from numpy.linalg import * from scipy.linalg import * M = np.array([[1, 1, 0], [1, 1, 0], [0, 0, 1]]) print("M^T=\n",M.transpose()) # transpose matrix print("Det (M) =",det(M)) # determinant print("Vectors in the Kernel (Nullspace)=\n",null_space(M)) # null space unit matrix eigen = eig(M) # eigen values and vectors print("eigenvectors and eigenvalues\n",eigen) # first index is eigen values print("Eigenvalues = \n",eigen[0]) # Columns are normalized eigenvectors. Transpose is used to convert them into rows print("Eigenvectors = \n",eigen[1].T) #The rotation matrix is made out of the rows of the eigenvectors Q=eigen[1].T print("Q =\n",Q) # @ is matrix multiply print("Q.M.Q^T=\n",Q@M@Q.transpose()) # this also works print("Q.M.Q^T=\n",

View Sympy Python Code

from sympy.matrices import Matrix import sympy as sp sp.init_printing(use_latex = "mathjax") M = Matrix([[1, 1, 0], [1, 1, 0], [0, 0, 1]]) # transpose matrix display("Transpose =",M.T) # determinant display("Det=",M.det()) # null space display("Vectors in the Kernel (Nullspace) =",M.nullspace()) # eigen values display("Eigenvalues=",M.eigenvals()) # eigen vectors vector = M.eigenvects() display("Eigenvalues and Eigenvectors =",vector) ev = [i[2][0].T for i in vector] display("extracted eigenvectors",ev) #The function Matrix ensures the list is a sympy matrix Q = Matrix([i/i.norm() for i in ev]) display("normalized eigenvectors",Q) display("Check that triple product is positive") Q[0,:].dot(Q[1,:].cross(Q[2,:])) # matrix multiply display("Diagonalized matrix = Q.M.Q^T",Q*M*Q.T) Q2 = Matrix([Q[2,:],Q[0,:],Q[1,:]]) display("A different order could be used for Q",Q2) display("Diagonalized matrix = Q.M.Q^T",Q2*M*Q2.T)

Example 2

Consider the vectors x=\{1,1,1\}, u=\{0.6,0.8,0\}, v=\{-0.8,0.6,0\}, and w=\{0,0,1\}. Consider the linear map represented by the matrix:

    \[ M=\left(\begin{matrix}2&1&0\\1&5&2\\2&-1&3\end{matrix}\right) \]

  • Find the components of the vector y, the image of the vector x under the linear map M.
  • Show that the vectors u, v, and w form an orthonormal basis set.
  • Find the components of x', y' and M' if the basis set B'=\{u,v,w\} is chosen for the coordinate system.

The components of y are:

    \[ y=Mx=\{3,8,4\} \]

The vectors u, v, and w are orthogonal to each other and the norm of each is equal to 1. In addition, the order u, v, and w follows the right hand orientation. Setting B'=\{u,v,w\} the coordinate transformation matrix is:

    \[ Q=\left(\begin{matrix}u\cdot e_1&u\cdot e_2&u\cdot e_3\\v\cdot e_1&v\cdot e_2&v\cdot e_3\\w\cdot e_1&w\cdot e_2&w\cdot e_3\end{matrix}\right)=\left(\begin{matrix}0.6&0.8&0\\-0.8&0.6&0\\0&0&1\end{matrix}\right) \]

Therefore, the components of the vectors x', y', and the matrix M' are:

    \[ x'=Qx=\{1.4,-0.2,1\}\qquad y'=Qy=\{8.2,2.4,4\} \]

    \[ M'=QMQ^T=\left(\begin{matrix}4.88&1.16&1.6\\1.16&2.12&1.2\\0.4&-2.2&3\end{matrix}\right) \]

View Mathematica Code

x = {1, 1, 1};
M = {{2, 1, 0}, {1, 5, 2}, {2, -1, 3}};
y = M.x;
y // MatrixForm  
u = {3/5, 4/5, 0};
v = {-4/5, 3/5, 0};
w = {0, 0, 1.};
Q = {u, v, w};
Q // MatrixForm  
xp = Q.x;
xp // MatrixForm  
yp = Q.y;
yp // MatrixForm  
Mp = Q.M.Transpose[Q];
Mp // MatrixForm  
Mp.xp // MatrixForm  

View Numpy Python Code

import numpy as np
import numpy as np
from numpy.linalg import *
x = np.array([1, 1, 1]) 
M = np.array([[2, 1, 0], [1, 5, 2], [2, -1, 3]])
# matrix multiply
y = np.matmul(M,x)
# same operation
y = M@x
u = np.array([3/5, 4/5, 0])
v = np.array([-4/5, 3/5, 0])
w = np.array([0, 0, 1])
print("Check length of vectors")
# @ also works as dot product
print("Check orthogonality")
print("u.v =",u@v)
print("u.w =",u@w)
print("v.w =",v@w)
print("Check orientation")
# Q will be a 3 x 3
Q = u
# Adds row to matrix
Q = np.vstack([Q, v])
Q = np.vstack([Q, w])
#Alternatively, Q can be defined as:
xp = Q@x
yp = Q@y
Mp = Q@M@Q.transpose()
print("y'= Qy\n",yp)

View Sympy Python Code

from sympy.matrices import Matrix
import sympy as sp
sp.init_printing(use_latex = "mathjax")
# vector []
x = Matrix([1, 1, 1])
M = Matrix([[2, 1, 0], [1, 5, 2], [2, -1, 3]])
y = M*x
# you need [[]] to use matrix operations
ul = [3/5, 4/5, 0]
vl = [-4/5, 3/5, 0]
wl = [0, 0, 1]
u = Matrix(ul)
v = Matrix(vl)
w = Matrix(wl)
display("Check the length of each vector")
display("Check the mutual orthogonality")
display("Check the orientation")
Q = Matrix([ul,vl,wl])
xp = Q*x
Mp = Q*M*Q.T
yp1 = Q*y
yp2 = Mp*xp
display("Change of coordinate system matrix=",Q)
display("x in new coordinate system=x'=Qx",xp)
display("M in new coordinate system=M'=QMQ^T",Mp)
display("y in new coordinate system=y'=Qy",yp1)
display("y in new coordinate system=y'=M'x'",yp2)

Example 3

In the following code, the rotation matrix Q\in\mathbb{M}^2 is defined using the function “RotationMatrix[angle]”. Notice that the angle input is automatically set at radians unless the command “Degree” is used. Because of the symbolic notation of Mathematica, the function FullSimplify[] is used to show that the rotation matrix preserves the norm of the vector u=\{2,2\} after rotation and that the rotation angle between u and its image v is exactly 20 degrees.

View Mathematica Code

(*The following is a rotation matrix using the angle Pi/6 in radians*)
(*The following is a rotation matrix using 20 degrees*)

View Numpy Python Code

import numpy as np
from numpy.linalg import *
# input degrees get radians
theta = np.radians(20) 
c, s = np.cos(theta), np.sin(theta)
# using the 2D rotation formula
Q = np.array([[c, -s], [s, c]]) 
print("Q =\n",Q)
u = np.array([2, 2])
v = Q@u
print("v =",v)
print("|u| =",norm(u))
print("|v| =",norm(v))
# using angle formula
print("theta(rad) =",th) 

View Sympy Python Code

from sympy.matrices import Matrix from mpmath import radians# degree radius conversion import sympy as sp from sympy import pi, simplify sp.init_printing(use_latex = "mathjax") # The following is a general rotation matrix with an angle rot in the counterclockwise direction rot = sp.symbols("rot") Q = Matrix([[sp.cos(rot),-sp.sin(rot)],[sp.sin(rot),sp.cos(rot)]]) display(Q) #Set rot = 20 degrees = 20 Pi/180 = pi/9 radians Q = Q.subs({rot:20*sp.pi/180}) display("Q =",Q) u = Matrix([2, 2]) v = Q*u display("v=",v) display("|u|=",u.norm()) display("|v|=",v.norm()) # simplifies the expression above display(simplify(v.norm())) # evaluates the expression above display(v.norm().evalf()) theta = sp.acos( # simplifies the expression above thetasimplified = simplify(theta) display("\u03B8(rad) = ",theta) display("\u03B8(rad) = ",thetasimplified) display("\u03B8(rad) = ",thetasimplified.evalf())

Example 4

In the following code, an array of 4 points is defined and used to draw a triangle. Then, a new array is calculated by applying a rotation of 60 degrees to every point and thus a new triangle rotated by 60 degrees is defined. Finally, two triangles are created using the Polygon function and viewed using the Graphics function.

View Mathematica Code

(*The following line stores the array of 4 vertices in the variable Points*)
(*The following line rotates each of the 4 elements in Points using the rotation matrix Q, then, forms a new array of 4 rotated vertices in the variable Points2. The new array is formed using the Table command*)
(*The following lines define two polygons c and c2 using the vertices defined in the variable Points and Points2*)
(* The following line views the objects c and c2 with the default graphics formatting*)
(*The following line views the objects while applying specific graphics formatting*)

View Python Code using Matplotlib & Numpy

import numpy as np
from numpy.linalg import *
from matplotlib import pyplot as plt
%matplotlib inline
# input needs radians
theta = np.radians(60) 
c, s = np.cos(theta), np.sin(theta)
# rotation matrix
Q = np.array([[c, -s], [s, c]]) 
# array of points
points = np.array([[0, 1],
                   [5, 1],
                   [2, 3], 
                   [0, 1]])
# array of rotated points

points2 = np.array([np.matmul(Q,i) for i in points])

print("Original triangle(blue)\n",points)
print("Rotation matrix\n",Q)
print("Rotated triangle(orange)\n",points2)
fig, ax = plt.subplots()
ax.plot(points[:,0], points[:,1])
ax.plot(points2[:,0], points2[:,1])
ax.grid(True, which='both')
ax.axhline(y = 0, color = 'k')
ax.axvline(x = 0, color = 'k')

Example 5

The function “RotationMatrix[angle,vector]” can be used to create a rotation matrix create Q\in\mathbb{M}^3 that is a rotation around a particular vector. You can use two- or three-dimensional graphics objects to visualize the effect of the rotation matrices. For example, in the following code, a rotation matrix Q with an angle of 60 degrees around the vector e_1=\{1,0,0\} is first defined. Then a unit cube is created and transformed by a geometric transformation of the original cube.

View Mathematica Code

thx = 60 Degree
Qx = RotationMatrix[thx, {1, 0, 0}];
c = Cuboid[{0, 0, 0}, {1, 1, 1}];
c1 = GeometricTransformation[c, Qx]
(*Viewing the two objects using the default graphics formatting*)
Graphics3D[{c, , c1}, Axes -> True, AxesOrigin -> {0, 0, 0}]
(*Viewing the two objects using a specific formatting*)
Graphics3D[{GrayLevel[.3, 0.4], Specularity[White, 2], 
  EdgeForm[Thickness[0.005]], c, Specularity[White, 6], 
  EdgeForm[Thickness[0.01]], c1}, Axes -> True, 
 AxesOrigin -> {0, 0, 0}, Lighting -> "Neutral", 
 AxesStyle -> {Directive[Bold, 13], Directive[Bold, 13], 
   Directive[Bold, 13]}]

View Python Code using Matplotlib & Numpy

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
%matplotlib notebook
theta = np.radians(60) 
c, s = np.cos(theta), np.sin(theta)
# rotation on x axis
Q = np.array([[1, 0, 0], 
              [0, c, -s], 
              [0, s, c]])
# points for cube
points = np.array([[0, 0, 0],
                   [1, 0, 0],
                   [1, 1, 0],
                   [0, 1, 0],
                   [0, 0, 1],
                   [1, 0, 1],
                   [1, 1, 1],
                   [0, 1, 1]])
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
# plot surfaces and edges of the cube
r = [0,1]
# X = [[0,1],[0,1]]
# Y = [[0 0],[1 1]]
X, Y = np.meshgrid(r, r)
one = np.ones(4).reshape(2, 2)
zero = np.zeros(4).reshape(2, 2)
# display surface
ax.plot_surface(X,Y,one, alpha = 0.5, color = "black")
ax.plot_surface(X,Y,zero, alpha = 0.5, color = "black")
ax.plot_surface(X,zero,Y, alpha = 0.5, color = "black")
ax.plot_surface(X,one,Y, alpha = 0.5, color = "black")
ax.plot_surface(one,X,Y, alpha = 0.5, color = "black")
ax.plot_surface(zero,X,Y, alpha = 0.5, color = "black")
# display outline
ax.plot_wireframe(X,Y,one, alpha = 0.5, color = "white")
ax.plot_wireframe(X,Y,zero, alpha = 0.5, color = "white")
ax.plot_wireframe(X,zero,Y, alpha = 0.5, color = "white")
ax.plot_wireframe(X,one,Y, alpha = 0.5, color = "white")
ax.plot_wireframe(one,X,Y, alpha = 0.5, color = "white")
ax.plot_wireframe(zero,X,Y, alpha = 0.5, color = "white")
# plot points of cube
ax.scatter3D(points[:, 0], points[:, 1], points[:, 2], color = "black")
# rotation of cube on x axis
points2 = np.matmul(Q,points[0])
def rotFrame(X,Y,Z):
    temp = np.array([[X[i][j], Y[i][j], Z[i][j]] for i in range(X.shape[0]) for j in range(X.shape[1])])
    out = np.array([np.matmul(Q,i) for i in temp])
    # edit shape into 2 x 2
    _X = np.array([out[:,0]]).reshape(2,2)
    _Y = np.array([out[:,1]]).reshape(2,2)
    _Z = np.array([out[:,2]]).reshape(2,2)
    ax.plot_wireframe(_X,_Y,_Z, alpha=0.5,color="black")
    ax.plot_surface(_X,_Y,_Z, alpha=0.5,color = "red")
# rotate points
points2 = np.array([np.matmul(Q,i) for i in points])
# plot points
ax.scatter3D(points2[:, 0], points2[:, 1], points2[:, 2],color = "red")
print("Cube points(blue)\n", points)
print("Rotation matrix on x axis\n",Q)
print("Rotated cube points(red)\n", points2)

Example 6

In the following code, the rotation matrices Q_x, Q_y, and Q_z defined as rotations around e_1, e_2, and e_3, respectively, are created. A cuboid is then defined with opposite corners at \{0,0,0\}, and \{3,2,1\}. The function “Manipulate[]” is used to view the cuboid before and after applying the rotations Q_1 = Q_xQ_yQ_z (blue cuboid) and Q_2 =Q_zQ_yQ_x (red cuboid). Copy and paste the code into your Mathematica software, and move the sliders to change the values of the rotation angles. The order of consecutive rotations is important. The application of Q_1 on a vector is equivalent to rotating the vector first by Q_z, then by Q_y and finally by Q_x. The resulting vector is different if Q_2 is applied.

View Mathematica Code

Clear[thx, thy, thz]
Manipulate[Qx = RotationMatrix[thx, {1, 0, 0}];
Qy = RotationMatrix[thy, {0, 1, 0}];
Qz = RotationMatrix[thz, {0, 0, 1}];
c = Cuboid[{0, 0, 0}, {3, 2, 1}];
c1 = GeometricTransformation[c, Qx.Qy.Qz];
c2 = GeometricTransformation[c, Qz.Qy.Qx];
Graphics3D[{c, {Blue, c1}, {Red, c2}}, AxesStyle -> {Directive[Bold, 13], Directive[Bold, 13], Directive[Bold, 13]}, AxesLabel -> {"x", "y", "z"}, Axes -> True, AxesOrigin -> {0, 0, 0}], {thx, 0, 2 Pi}, {thy, 0, 2 Pi}, {thz, 0, 2 Pi}]

View Python Code using Matplotlib & Numpy

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider
from mpl_toolkits.mplot3d import Axes3D
%matplotlib notebook
class plot3dCube(object):
    def __init__(self, origin, length, color):
        # origin[x,y,z], length[Lx,Ly,Lz], 
        # color[original[surface & point, edge], Qxyz[surface & point, edge], Qzxy[surface & point, edge]
        Lx,Ly,Lz = length
        x1,y1,z1 = origin
        origin1 = x2,y2,z2 = [length[i]+origin[i] for i in range(3)]
        # for A as X,Y,Z
        # A_1212 uses [[x1, x2][x1,x2]]
        # A_1122 is just X_1.T
        # A_1111 all x1
        # A_2222 all x2
        r = [x1, x2]
        X_1212 = np.array([r,r])
        X_1111 = np.ones(4).reshape(2, 2)*x1
        X_2222 = np.ones(4).reshape(2, 2)*x2
        r = [y1, y2]
        Y_1212, Y_1122 = np.meshgrid(r, r)
        Y_1111 = np.ones(4).reshape(2, 2)*y1
        Y_2222 = np.ones(4).reshape(2, 2)*y2
        r = [z1, z2]
        Z_1122 = np.array([r,r]).transpose()
        Z_1111 = np.ones(4).reshape(2, 2)*z1
        Z_2222 = np.ones(4).reshape(2, 2)*z2
        # points of the cube
        self.points = np.array([[x1, y1, z1],
                               [x2, y1, z1],
                               [x2, y2, z1],
                               [x1, y2, z1],
                               [x1, y1, z2],
                               [x2, y1, z2],
                               [x2, y2, z2],
                               [x1, y2, z2]])

        # square points for surface, edges
        self.sqrP = [[X_1212,Y_1122,Z_1111],[X_1212,Y_1122,Z_2222],
        # create plot figure
        self.fig = plt.figure(figsize=(6,7)) = self.fig.add_subplot(111, projection='3d')
        # range of axis
        axis = origin+origin1
        # get abolsute for each axis length
        axis =  [abs(i) for i in axis] 
        # get two highes axis lengths
        for i in range(len(axis)-2):
        # pythagorean theorem
        l = np.sqrt(sum([i**2 for i in axis])), l), l), l)'X')'Y')'Z')
        # surface frame and edge variable names
        self.s = ["self.surfacex","self.surfacez"]
        self.e = ["self.edgex","self.edgez"]
        # set color 
        self.ogColor, self.QxQyQzColor, self.QzQyQxColor = color
        # Construct plot, surfaces and edges
        # plot initial points
        # black is original, does not move =[:,0],self.points[:,1], self.points[:,2],color = self.ogColor[0])
        # blue is Q = Qx*Qy*Qz
        self.scx =[:,0],self.points[:,1], self.points[:,2], color = self.QxQyQzColor[0] )
        # red is Q = Qz*Qy*Qx
        self.scz =[:,0],self.points[:,1], self.points[:,2],color = self.QzQyQxColor[0])
        # plot surface and edges
        # Original cube(does not move)
        self.color = self.ogColor
        # dictionary of surfaces and edges
        self.dFrm = {}
        # surface variable name
        surface = "self.surface"
        # edge variable name
        edge = "self.edge"
        # original plot
        for i in range(len(self.sqrP)):
            # number
            n = str(i)
            self.dFrm[surface+n], self.dFrm[edge+n] = self.initFrame(self.sqrP[i][:])
        for i in range(len(self.s)):
            # QxQyQz plot
            if(i == 0):
                self.color = self.QxQyQzColor
            # QzQyQx plot
                self.color = self.QzQyQxColor
            surface = self.s[i]
            edge = self.e[i]
            # generate each surface and edge
            for j in range(len(self.sqrP)):
                n = str(j)
                self.dFrm[surface+n], self.dFrm[edge+n] = self.initFrame(self.sqrP[j][:])
        # slider plot
        # adjust plot
        plt.subplots_adjust(left = 0.1, bottom = 0.45)
        # input the position of sliders
        xSlider = plt.axes([0.2,0.2,0.5,0.03])
        ySlider = plt.axes([0.2,0.15,0.5,0.03])
        zSlider = plt.axes([0.2,0.1,0.5,0.03])
        xSlider.set_xticks(np.array([90,180,270]), minor = True)
        ySlider.set_xticks(np.array([90,180,270]), minor = True)
        zSlider.set_xticks(np.array([90,180,270]), minor = True)
        # input values and update graph
        self.slider1 = Slider(xSlider, 'x angle', 0, 360, valinit = 0, valstep = 1)
        self.slider2 = Slider(ySlider, 'y angle', 0, 360, valinit = 0, valstep = 1)
        self.slider3 = Slider(zSlider, 'z angle', 0, 360, valinit = 0, valstep = 1)
        # updates the graph when input is changes
    # determins the rotation matricies from inputed angles
    def setMatrix(self, x, y, z):
        xtheta = np.radians(x) 
        ytheta = np.radians(y) 
        ztheta = np.radians(z)
        # cos sin values
        cx, sx = np.cos(xtheta), np.sin(xtheta)
        cy, sy = np.cos(ytheta), np.sin(ytheta)
        cz, sz = np.cos(ztheta), np.sin(ztheta)
        # x rotation matrix
        self.Qx = np.array([[1, 0, 0], 
                            [0, cx, -sx], 
                            [0, sx, cx]])
        # y rotation matrix
        self.Qy = np.array([[cy, 0, sy], 
                            [0, 1, 0], 
                            [-sy, 0, cy]])
        # z rotation matrix
        self.Qz = np.array([[cz, -sz, 0], 
                            [sz, cz, 0], 
                            [0, 0, 1]])
        # QxQyQz Matrix
        self.QxQyQz = self.Qx@self.Qy@self.Qz
        # QzQyQx Matrix
        self.QzQyQx = self.Qz@self.Qy@self.Qx
    # When you first draw the frame and edges
    def initFrame(self, sqrP):
        surface =[0],sqrP[1],sqrP[2],alpha=0.5,color=self.color[0])
        edge =[0],sqrP[1],sqrP[2],alpha=0.5,color=self.color[1])
        return surface, edge
    # rotate matrix * original to get new surface and edges
    def rotFrame(self, surface, edge, X, Y, Z):
        #destory previous surfaces and edges
        # X, Y, Z are a 2x2 matrix
        # first convert the 3 2x2 matricies into a 1 x 3 vector
        temp = np.array([[X[i][j], Y[i][j], Z[i][j]] for i in range(X.shape[0]) for j in range(X.shape[1])])
        # QxQyQz plot
        if(self.color == self.QxQyQzColor):
            out = np.array([np.matmul(self.QxQyQz,i) for i in temp])
        # QzQyQx plot
        elif(self.color == self.QzQyQxColor):
            out = np.array([np.matmul(self.QzQyQx,i) for i in temp])
        # edit shape into 2 x 2
        _X = np.array([out[:,0]]).reshape(2,2)
        _Y = np.array([out[:,1]]).reshape(2,2)
        _Z = np.array([out[:,2]]).reshape(2,2)
        # plot surfaces and edges
        surface =,_Y,_Z, alpha = 0.5, color = self.color[0])
        edge =,_Y,_Z, alpha = 0.5, color = self.color[1])
        return surface, edge
    # creates the rotated frame, then deletes the old one and adds the new one
    def rotFrames(self):        
        for i in range(len(self.s)):
            # QxQyQz cube
            if(i == 0):
                self.color = self.QxQyQzColor
            # QzQyQx cube
                self.color = self.QzQyQxColor
            surface = self.s[i]
            edge = self.e[i]
            # destroy current surface and edge, new surface and edge
            for j in range(6):
                n = str(j)
                self.dFrm[surface+n], self.dFrm[edge+n]= self.rotFrame(self.dFrm[surface+n],self.dFrm[edge+n], 
    # rotates the points of the scatter plot
    def rotPoints(self):
        # QxQyQz points
        self.points2 = np.array([np.matmul(self.QxQyQz,i) for i in self.points])
        # QzQyQx points
        self.points3 = np.array([np.matmul(self.QzQyQx,i) for i in self.points])
        # plot points
        # QxQyQz plot
        self.scx._offsets3d = (self.points2[:, 0], self.points2[:, 1], self.points2[:, 2])
        # QzQyQx plot
        self.scz._offsets3d = (self.points3[:, 0], self.points3[:, 1], self.points3[:, 2])
    def updateGraph(self, event):
        # change matrix
        # print points
        # print surfaces and edges
# main function
# NOTE: spamming the inputs will freeze the plot
p = plot3dCube([0,0,0], [3,2,1],[["black","white"],["blue","blue"],["red","red"]])

Example 7

In the following code, two reflection matrices are created using the “ReflectionMatrix[vector]” function. Reflection is applied across the plane perpendicular to the vector specified. The blue and red triangles are reflections across the planes passing through the origin and perpendicular to the blue and red arrow directions, respectively.

View Mathematica Code

(*In gray tones*)
(*In colour*)

View Python Code using Matplotlib & Numpy

import numpy as np
from numpy.linalg import *
from matplotlib import pyplot as plt
%matplotlib inline
# array of points
points = np.array([[0, 1],
                   [5, 1],
                   [2, 3],
                   [0, 1]]) 
print("Original triangle(black)\n",points)
fig, ax = plt.subplots()
ax.grid(True, which='both')

ax.axhline(y=0, color='k')
ax.axvline(x=0, color='k')
# relect points using the matrix
def refPlot(Q, color, out):
    points2 = np.array([np.matmul(Q,i) for i in points])
    ax.plot(points2[:,0], points2[:,1], color = color)
    print("Reflected triange", out, points2)
# plot original points
ax.plot(points[:,0], points[:,1], color = "black")
# arrow lines
ax.arrow(-5,0,10,0, color = "blue",length_includes_head = True,head_width=.5, head_length=.5)
ax.arrow(-5,-5,10,10, color = "red",length_includes_head = True,head_width=.5, head_length=.5)
ax.arrow(5,0,-10,0, color = "blue",length_includes_head = True,head_width=.5, head_length=.5)
ax.arrow(5,5,-10,-10, color = "red",length_includes_head = True,head_width=.5, head_length=.5)
# plot reflected points
# matrix for reflecting on the y axis
refPlot(np.array([[-1,0],[0,1]]), "blue","on y axis(blue)\n")
# matrix for x = y
refPlot(np.array([[0,-1],[-1,0]]),"red","for x = y(red)\n")  


  1. Show that a matrix M\in\mathbb{M}^3 is not invertible if and only if 0 is an eigenvalue for M. In this case, what can you say about the set \ker{M}.
  2. Find the determinant, the eigenvalues, and the eigenvectors of the following matrices. If a matrix is not invertible, then find its kernel. If a matrix is invertible, then, find its inverse:

        \[ \left(\begin{matrix}1&1\\-1&-1\end{matrix}\right)\qquad \left(\begin{matrix}1&1\\0&-1\end{matrix}\right)\qquad \left(\begin{matrix}5&0&0\\0&2&-1\\1&2&5\end{matrix}\right)\qquad \left(\begin{matrix}5&0&0\\0&2&-1\\10&2&-1\end{matrix}\right) \]

  3. Repeat the previous question for the following matrices:

        \[ \left(\begin{matrix}3&2&1\\4&6&5\\3&8&4\end{matrix}\right)\qquad \left(\begin{matrix}1&0&0\\0&2&-1\\1&2&5\end{matrix}\right)\qquad \left(\begin{matrix}1&0&0\\0&-2&-1\\5&2&1\end{matrix}\right) \]

  4. Consider the vectors x=\{1,0,0\}, y=\{0,1,0\}, and z=\{1,1,1\}. Find the volume of the parallelepiped formed by the three vectors. Also, find the volume of the parallelepiped formed when the three vectors are linearly mapped using the matrices M_a, and M_b defined below. Comment on the results.

        \[ M_a=\left(\begin{matrix}1.1&0.1&0\\0&0.9&0\\0&0&0.9\end{matrix}\right)\qquad M_b=\left(\begin{matrix}0&1.1&0\\0&1&0\\0&0&1\end{matrix}\right) \]

  5. Consider a parallelepiped with edges AB, AC, and AD where A=(-3,-2,2), B=(4,2,1), C=(0,1,4), and D=(0,0,7). Determine the new volume of the parallelpiped after a transformation of the space by the matrix M:

        \[ M=\left(\begin{matrix}3&2&1\\0&2&1\\-1&-1&-1\end{matrix}\right) \]

    Comment on the sign of the resulting volume.
  6. Chose a value for M_{11} in the following matrices so that each matrix is not invertible. Then, find the kernel in each case:

        \[ M_a=\left(\begin{matrix}M_{11}&5&5\\-3&5&-1\\0&2&-1\end{matrix}\right)\qquad M_b=\left(\begin{matrix}M_{11}&2&3&1\\-1&-2&1&-2\\1&3&1&-5\\5&2&1&7\end{matrix}\right) \]

  7. Use Mathematica Software to draw a two-dimensional polygon with five sides, and then use the table command to create 10 copies of the polygon rotated with an angle \frac{2\pi}{10} between each copy. Finally, use the graphics command to view the 10 polygons you drew.
  8. The shown rectangle has a length of 2 units and height of 4 units. Find the coordinates of its vertices in the orthonormal basis set B=\{e_1,e_2\}. Find the coordinates of the vertices in the coordinate system defined by the basis set B'=\{e'_1,e'_2\}.
  9. The shown rectangle has a length of 2 units and height of 4 units. Find the coordinates of its vertices if the rectangle is rotated counterclockwise by the angle shown in the figure. Comment on the difference between the linear mapping used in this problem and that used in the previous problem.
  10. Verify that the following matrix is an orthogonal matrix, and specify whether it is a rotation or a reflection.

        \[ Q=\left(\begin{matrix}\frac{3}{4}&-\frac{\sqrt{3}}{4}&\frac{1}{2}\\\frac{3\sqrt{3}}{8}&\frac{5}{8}&-\frac{\sqrt{3}}{4}\\-\frac{1}{8}&\frac{3\sqrt{3}}{8}&\frac{3}{4}\end{matrix}\right) \]

  11. Find the components Q_{11}, Q_{12}, and Q_{13} so that the following is a rotation matrix:

        \[Q=\left(\begin{matrix}Q_{11}&Q_{12}&Q_{13}\\\frac{3}{8}+\frac{\sqrt{3}}{4}&\frac{3}{4}-\frac{\sqrt{3}}{8}&-\frac{1}{4}\\\frac{1}{4}-\frac{3\sqrt{3}}{8}&\frac{3}{8}+\frac{\sqrt{3}}{4}&\frac{\sqrt{3}}{4}\end{matrix}\right) \]

  12. Find the components Q_{11}, Q_{12}, and Q_{13} so that the following is a reflection matrix:


  13. Find two possible combinations for the missing components in Q so that it is a rotation matrix:

        \[Q=\left(\begin{matrix}0.1&0.2&Q_{13}\\0.1&Q_{22}&Q_{23}\\Q_{31}&Q_{32}&Q_{33}\end{matrix}\right) \]

  14. Find two possible combinations for the missing components in Q so that it is an orthogonal matrix associated with reflection:

        \[ Q=\left(\begin{matrix}0.1&0.2&Q_{13}\\0.1&Q_{22}&Q_{23}\\Q_{31}&Q_{32}&Q_{33}\end{matrix}\right) \]

  15. Consider the orthonormal basis set B=\{e_1,e_2,e_3\} and the matrix M:

        \[ M=\left(\begin{matrix}1&5&-2\\2&2&3\\-5&2&1\end{matrix}\right) \]

    • Let a=\{1,1,2\}, b=\{-1,1,0\}. Verify that a\cdot b=0 and find the vector c that is orthogonal to both a, and b. Find a new orthonormal basis set B' using the normalized vectors of a, b, and c.
    • Find the components of the matrix M' in the new orthonormal basis set B'.
    • Find the three invariants of M and M' and verify that they are equal.
    • Find the eigenvalues of M and M' and verify that they are equal.
    • Find the components of the eigenvectors of M and the eigenvectors of M' and comment on whether they are the same vectors or not.
  16. Repeat the previous question with a=\{2,1,1\}, b=\{0,1,-1\}, and:

        \[ M=\left(\begin{matrix}-2&5&1\\3&2&2\\1&2&-5\end{matrix}\right) \]

  17. Consider the orthonormal basis set B=\{e_1,e_2,e_3\} and the matrix M:

        \[ M=\left(\begin{matrix}3&0&0\\0&2&1\\0&0&4\end{matrix}\right) \]

    If the orthonormal basis set B'=\{-e_2,e_1,e_3\} is used as the coordinate system, find the components of M' in the new coordinate system.
  18. Consider the symmetric matrix S:

        \[ S=\left(\begin{matrix}1&0&-2\\0&2&0\\-2&0&1\end{matrix}\right) \]

    • Find the eigenvalues and eigenvectors of S.
    • Find a new coordinate system B' such that the matrix of components S' in the new coordinate system is a diagonal matrix.
  19. Identify the positive definite and semi-positive definite symmetric matrices in the following:

        \[ \left(\begin{matrix}1&0&-2\\0&2&0\\-2&0&1\end{matrix}\right)\qquad \left(\begin{matrix}1&0&2\\0&2&0\\2&0&1\end{matrix}\right) \qquad \left(\begin{matrix}1&0&-2\\0&2&0\\-2&0&0\end{matrix}\right)\qquad \left(\begin{matrix}-1&0&-2\\0&2&0\\-2&0&1\end{matrix}\right) \]

  20. Find the missing values in the components of the orthogonal matrix Q so that it represents a change of basis while maintaining the proper orientation.

        \[ \left(\begin{matrix}\frac{1}{\sqrt{3}}&\frac{1}{\sqrt{3}}&\frac{1}{\sqrt{3}}\\?&?&?\\0&?&\frac{1}{\sqrt{2}}\end{matrix}\right) \]

    Then, find the components of the identity matrix when a coordinate transformation using Q is applied. Comment on the results.
  21. Find the eigenvalues and eigenvectors of the following symmetric matrices and then perform the diagonalization process for each.

        \[ \left(\begin{matrix}11&4&0\\4&5&0\\0&0&7\end{matrix}\right)\qquad \left(\begin{matrix}7&0&-2\\0&5&0\\-2&0&4\end{matrix}\right) \]

  22. The figure below shows a square with dimension t. Determine the transformation matrix M:\mathbb{R}^2\rightarrow\mathbb{R}^2 applied to the object to produce the image shown.
  23. Let a, b, and c\in\mathbb{R}^3 be three vectors that are linearly independent. Using the properties of the dot product, construct an orthonormal basis set as a function of a, b, and c. (The construction is referred to as: Gram-Schmidt Process)
  24. Let a,b\in\mathbb{R}^3. Find an example of a matrix M\in\mathbb{M}^3 such that M(a\times b)\neq Ma\times Mb. Then, show that if Q\in\mathbb{R}^3 is a rotation matrix, then Q(a\times b)=Qa\times Qb.
  25. Using Einstein summation convention, and assuming that the underlying space is the Euclidean space \mathbb{R}^3, show that the following relations hold true for the Kronecker Delta \delta_{ij} and the alternator \varepsilon_{ijk}:
    • \delta_{ii}=3.
    • \delta_{ik}\varepsilon_{ikm}=0.
    • \varepsilon_{iks}\varepsilon_{mks}=2\delta_{im}.
    • \varepsilon_{ikm}\varepsilon_{ikm}=6.
    • \varepsilon_{iks}\varepsilon_{mps}=\delta_{im}\delta_{kp}-\delta_{ip}\delta_{km}.
  26. Write the following expressions out in full assuming that the underlying space is the Euclidean space \mathbb{R}^3:
    • c=d_{ijkl}\delta_{jk}\delta_{il}.
    • b_i=(a_{ij}+a_{ji})c_j.
    • a_i=\varepsilon_{ijk}c_jd_k.
  27. Write the following expressions in a compact form using index notation and the Einstein summation convention:
    1.     \[ \begin{split}c_{11}x_1+c_{12}x_2+c_{13}x_3 & =d_1\\c_{21}x_1+c_{22}x_2+c_{23}x_3&=d_2 \\ c_{31}x_1+c_{32}x_2+c_{33}x_3&=d_3\end{split} \]

    2. a=c_{11}x_1^2+c_{22}x_2^2+c_{33}x_3^2+(c_{12}+c_{21})x_1x_2+(c_{13}+c_{31})x_1x_3+(c_{23}+c_{32})x_2x_3.
    3. In the following expressions assume that \varepsilon=\varepsilon_{11}+\varepsilon_{22}+\varepsilon_{33}

          \[\begin{split} \sigma_{11}&=2\mu\varepsilon_{11}+\lambda\varepsilon\\ \sigma_{22}&=2\mu\varepsilon_{22}+\lambda\varepsilon\\ \sigma_{33}&=2\mu\varepsilon_{33}+\lambda\varepsilon\\ \sigma_{12}=\sigma_{21}&=2\mu\varepsilon_{12}=2\mu\varepsilon_{21}\\ \sigma_{13}=\sigma_{31}&=2\mu\varepsilon_{13}=2\mu\varepsilon_{31}\\ \sigma_{32}=\sigma_{23}&=2\mu\varepsilon_{23}=2\mu\varepsilon_{32} \end{split}\]

  28. Show that symmetric and antisymmetric matrices stay symmetric and antisymmetric, respectively, under any orthogonal coordinate transformation.
    1. Using the definitions of symmetric and antisymmetric tensors without reference to components.
    2. Using the component forms of symmetric and antisymmetric matrices.
  29. In a three dimensional Euclidean vector space, how many independent components will the following tensors have:
    • A “completely symmetric” third order tensor.
    • A “completely symmetric” fourth order tensor.
    “Completely symmetric” means that components having indices with the same numerical values are equal regardless of the order. For example, if C is a completely symmetric fourth order tensor, then: C_{1213}=C_{1132}=C_{1231}=C_{3211}\cdots etc.
  30. Show that if A and B are symmetric matrices, then AB is not necessarily a symmetric matrix. (Hint: Find a counter example). On the other hand, show that if A and B are symmetric matrices that have the same eigenvectors (also called “coaxial”), then AB and BA are symmetric.
  31. Show that if A\in\mathbb{M}^3 is a symmetric matrix, then \forall B\in\mathbb{M}^3, the matrix C=BAB^T is symmetric.
  32. Let A,B,C,I\in\mathbb{M}^n and I is the identity matrix. Using the algebraic structure of matrices, show that if BA=I and AC=I, then B=C. The matrix B is referred to as the inverse of A and is denoted A^{-1}.
  33. Let S\in\mathbb{M}^n be a symmetric matrix. Let \lambda_{min} and \lambda_{max} be the minimum and maximum eigenvalues of S. Show that \forall a\in\mathbb{R}^n:\lambda_{min}\leq \frac{a\cdot Sa}{a\cdot a}\leq \lambda_{max}. (The quantity \frac{a\cdot Sa}{a\cdot a} is referred to as the Rayleigh Quotient)
  34. Let A,B\in\mathbb{M}^n. Let S\in\mathbb{M}^n be an invertible symmetric matrix. Show the following:
    • (AB)^T=B^TA^T.
    • (S^T)^{-1}=(S^{-1})^T.
    • S^{-1} is symmetric.
  35. Let S be a symmetric matrix. Let L be another matrix. Find the restriction on L to ensure that the matrix SL is symmetric, i.e., that SL=L^TS. (Hint: in a coordinate system of the eigenvectors of S the ratios between the off diagonal components of L is equal to the ratios between the corresponding eigenvalues of S)
  36. As will be discussed later, the stress at a point can be described as a symmetric matrix with the following form:

        \[ \sigma=\begin{pmatrix}\sigma_{11}&\sigma_{12}&\sigma_{13}\\\sigma_{12}&\sigma_{22}&\sigma_{23}\\\sigma_{13}&\sigma_{23}&\sigma_{33}\end{pmatrix} \]

    Assume a change of coordinates described by the following rotation matrix

        \[Q=\begin{pmatrix}\cos{(\theta)}&\sin{(\theta)}&0\\-\sin{(\theta)}&\cos{(\theta)}&0\\0&0&1\end{pmatrix} \]

    In the new coordinate system, the comonents of \sigma will have the following form:

        \[\sigma=Q \sigma Q^T\]

    If a vector representation of the stress is adopted as follows:

        \[ \sigma_v=\begin{pmatrix}\sigma_{11}\\\sigma_{22}\\\sigma_{33}\\\sigma_{12}\\\sigma_{13}\\\sigma_{23}\end{pmatrix} \]

    Then, show that the components of the vector after transformation are given by:

        \[\sigma_v'=Q_v \sigma_v\]

    where Q_v has the following form:

        \[ Q_v= \left( \begin{array}{cccccc} \cos ^2(\theta) & \sin ^2(\theta) & 0 & \sin (2 \theta) & 0 & 0 \\ \sin ^2(\theta) & \cos ^2(\theta) & 0 & -\sin (2 \theta) & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 \\ -\frac{1}{2} \sin (2 \theta) & \frac{1}{2} \sin (2 \theta) & 0 & \cos (2 \theta) & 0 & 0 \\ 0 & 0 & 0 & 0 & \cos (\theta) & \sin (\theta) \\ 0 & 0 & 0 & 0 & -\sin (\theta) & \cos (\theta) \\ \end{array} \right) \]

Leave a Reply

Your email address will not be published.