Linear Maps Between Vector Spaces: Examples and Problems
Examples and Problems
Example 1
Consider the symmetric matrix:
Find , the determinant of , the kernel of , the eigenvalues and eigenvectors of , and find the coordinate transformation in which is diagonal.
Solution
Since is symmetric, therefore, . The determinant of 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, . The kernel of can be obtained by finding the possible forms for the vector that would satisfy the following equation:
Therefore:
By setting , we have . Therefore, the kernel of has the form:
To find the eigenvalues of we find the possible values for that would make the matrix not invertible. In other words, we solve for that would satisfy:
Therefore:
Therefore, the possible three eigenvalues are: , and . Note that since is not invertible, is automatically an eigenvalue for .
The eigenvector corresponding to the eigenvalue can be found as follows:
which is the same equation to find the vectors of the kernel. So, a normalized vector in the kernel would satisfy this equation. Therefore,
The eigenvector corresponding to the eigenvalue can be found as follows:
Therefore, we have the following three equations:
Therefore, the normalized components of the second eigenvector are:
Since is symmetric, the third eigenvector has to be normal to the first and second eigenvectors. So, we can simply find a vector normal to and . Or we can solve the equation:
Therefore, we have the following three equations:
Therefore, the normalized components of the third eigenvector are:
The coordinate system in which the representation of the matrix is diagonal is the coordinate system made of the three normalized eigenvectors of . Setting , the coordinate transformation matrix has the form:
Note that the order of the vectors in was chosen so that is a rotation matrix, i.e., the vectors of have to obey the right hand orientation. Therefore, the components of when using as the basis set are:
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 .
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 // MatrixFormView 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",Q.dot(M).dot(Q.transpose()))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 , and . Consider the linear map represented by the matrix:
 Find the components of the vector , the image of the vector under the linear map .
 Show that the vectors , and form an orthonormal basis set.
 Find the components of and if the basis set is chosen for the coordinate system.
Solution
The components of are:
The vectors , and are orthogonal to each other and the norm of each is equal to 1. In addition, the order , and follows the right hand orientation. Setting the coordinate transformation matrix is:
Therefore, the components of the vectors , and the matrix are:
View Mathematica Code
x = {1, 1, 1}; M = {{2, 1, 0}, {1, 5, 2}, {2, 1, 3}}; Print["y=Mx"] y = M.x; y // MatrixForm u = {3/5, 4/5, 0}; v = {4/5, 3/5, 0}; w = {0, 0, 1.}; Norm[u] Norm[v] Norm[w] u.v u.w v.w Q = {u, v, w}; Q // MatrixForm xp = Q.x; Print["x'"] xp // MatrixForm yp = Q.y; Print["y'"] yp // MatrixForm Mp = Q.M.Transpose[Q]; Print["M'"] Mp // MatrixForm Print["M'x'"] 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 print(y) 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") print("u=",norm(u)) print("v=",norm(v)) print("w=",norm(w)) # @ 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") print("u.v\u00D7w=",u@np.cross(v,w)) # Q will be a 3 x 3 Q = u # Adds row to matrix Q = np.vstack([Q, v]) Q = np.vstack([Q, w]) print("Q=\n",Q) #Alternatively, Q can be defined as: Q=np.array([u,v,w]) print("Q=\n",Q) print("x=\n",x) xp = Q@x yp = Q@y Mp = Q@M@Q.transpose() print("x'=\n",xp) print("y=\n",y) print("M=\n",M) print("M'=\n",Mp) print("y'=M'x'=\n",Mp@xp) 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 display(y) # 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(u.norm()) display(v.norm()) display(w.norm()) display("Check the mutual orthogonality") display(u.dot(v)) display(u.dot(w)) display(v.dot(w)) display("Check the orientation") display(u.dot(v.cross(w))) 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 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 after rotation and that the rotation angle between and its image is exactly 20 degrees.
View Mathematica Code
Q=RotationMatrix[Pi/6];
(*The following is a rotation matrix using 20 degrees*)
Q=RotationMatrix[20Degree];
u={2,2};
v=Q.u;
Norm[u]
Norm[v]
FullSimplify[Norm[v]]
VectorAngle[u,v]
FullSimplify[VectorAngle[u,v]]
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 th=np.arccos(u@v/norm(u)/norm(v)) print("theta(rad) =",th)
View Sympy Python Code
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
Q=RotationMatrix[th];
(*The following line stores the array of 4 vertices in the variable Points*)
Points={{0,1},{5,1},{2,3},{0,1}};
(*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*)
Points2=Table[Q.Points[[i]],{i,1,4}];
(*The following lines define two polygons c and c2 using the vertices defined in the variable Points and Points2*)
c=Polygon[Points];
c2=Polygon[Points2];
(* The following line views the objects c and c2 with the default graphics formatting*)
Graphics[{c,c2},Axes>True,AxesOrigin>{0,0}]
(*The following line views the objects while applying specific graphics formatting*)
Graphics[{Opacity[0.6],c,c2},Axes>True,AxesOrigin>{0,0},AxesStyle>{Directive[Bold,17],Directive[Bold,17]}]
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 that is a rotation around a particular vector. You can use two or threedimensional graphics objects to visualize the effect of the rotation matrices. For example, in the following code, a rotation matrix with an angle of 60 degrees around the vector 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") rotFrame(X,Y,one) rotFrame(X,Y,zero) rotFrame(X,zero,Y) rotFrame(X,one,Y) rotFrame(one,X,Y) rotFrame(zero,X,Y) # 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") ax.set_xlabel('X') ax.set_ylabel('Y') ax.set_zlabel('Z') plt.show() 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 , and defined as rotations around , and , respectively, are created. A cuboid is then defined with opposite corners at , and . The function “Manipulate[]” is used to view the cuboid before and after applying the rotations (blue cuboid) and (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 on a vector is equivalent to rotating the vector first by , then by and finally by . The resulting vector is different if is applied.
View Mathematica Code
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], [X_1212,Y_1111,Z_1122],[X_1212,Y_2222,Z_1122], [X_1111,Y_1212,Z_1122],[X_2222,Y_1212,Z_1122]] # create plot figure self.fig = plt.figure(figsize=(6,7)) self.ax = 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): axis.remove(min(axis)) # pythagorean theorem l = np.sqrt(sum([i**2 for i in axis])) self.ax.set_xlim3d(l, l) self.ax.set_ylim3d(l, l) self.ax.set_zlim3d(l, l) self.ax.set_xlabel('X') self.ax.set_ylabel('Y') self.ax.set_zlabel('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 self.sc = self.ax.scatter3D(self.points[:,0],self.points[:,1], self.points[:,2],color = self.ogColor[0]) # blue is Q = Qx*Qy*Qz self.scx = self.ax.scatter3D(self.points[:,0],self.points[:,1], self.points[:,2], color = self.QxQyQzColor[0] ) # red is Q = Qz*Qy*Qx self.scz = self.ax.scatter3D(self.points[:,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 else: 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 self.slider1.on_changed(self.updateGraph) self.slider2.on_changed(self.updateGraph) self.slider3.on_changed(self.updateGraph) # 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 = self.ax.plot_surface(sqrP[0],sqrP[1],sqrP[2],alpha=0.5,color=self.color[0]) edge = self.ax.plot_wireframe(sqrP[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 surface.remove() edge.remove() # 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 = self.ax.plot_surface(_X,_Y,_Z, alpha = 0.5, color = self.color[0]) edge = self.ax.plot_wireframe(_X,_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 else: 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], self.sqrP[j][0],self.sqrP[j][1],self.sqrP[j][2]) plt.draw() plt.pause(.01) # 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 self.setMatrix(self.slider1.val,self.slider2.val,self.slider3.val) # print points self.rotPoints() # print surfaces and edges self.rotFrames() # main function # NOTE: spamming the inputs will freeze the plot p = plot3dCube([0,0,0], [3,2,1],[["black","white"],["blue","blue"],["red","red"]]) #genInput()
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
Q2=ReflectionMatrix[{1,1}]
Points={{0,1},{5,1},{2,3},{0,1}};
Points1=Table[Q1.Points[[i]],{i,1,4}];
Points2=Table[Q2.Points[[i]],{i,1,4}];
L1=Arrow[{{5,0},{5,0}}]
L2=Arrow[{{5,5},{5,5}}]
c=Polygon[Points];
c1=Polygon[Points1];
c2=Polygon[Points2];
(*In gray tones*)
Graphics[{c,{GrayLevel[0.2],c1},{Arrowheads[{.1,.1}],{GrayLevel[0.2],L1}},{Arrowheads[{.1,.1}],{GrayLevel[0.5],L2}},{GrayLevel[0.5],c2}},Axes>True,AxesStyle>{Directive[Bold,13],Directive[Bold,13]},AxesOrigin>{0,0}]
(*In colour*)
Graphics[{c,{Blue,c1},{Arrowheads[{.1,.1}],{Blue,L1}},{Arrowheads[{.1,.1}],{Red,L2}},{Red,c2}},Axes>True,AxesOrigin>{0,0}]
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")
Problems
 Show that a matrix is not invertible if and only if 0 is an eigenvalue for . In this case, what can you say about the set .
 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:
 Repeat the previous question for the following matrices:
 Consider the vectors , and . 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 , and defined below. Comment on the results.
 Consider a parallelepiped with edges , and where , and . Determine the new volume of the parallelpiped after a transformation of the space by the matrix :

Chose a value for in the following matrices so that each matrix is not invertible. Then, find the kernel in each case:
 Use Mathematica Software to draw a twodimensional polygon with five sides, and then use the table command to create 10 copies of the polygon rotated with an angle between each copy. Finally, use the graphics command to view the 10 polygons you drew.
 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 . Find the coordinates of the vertices in the coordinate system defined by the basis set .
 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.
 Verify that the following matrix is an orthogonal matrix, and specify whether it is a rotation or a reflection.
 Find the components , and so that the following is a rotation matrix:
 Find the components , and so that the following is a reflection matrix:
 Find two possible combinations for the missing components in so that it is a rotation matrix:
 Find two possible combinations for the missing components in so that it is an orthogonal matrix associated with reflection:

Consider the orthonormal basis set and the matrix :
 Let . Verify that and find the vector that is orthogonal to both , and . Find a new orthonormal basis set using the normalized vectors of , and .
 Find the components of the matrix in the new orthonormal basis set .
 Find the three invariants of and and verify that they are equal.
 Find the eigenvalues of and and verify that they are equal.
 Find the components of the eigenvectors of and the eigenvectors of and comment on whether they are the same vectors or not.
 Repeat the previous question with , and:
 Consider the orthonormal basis set and the matrix :
 Consider the symmetric matrix :
 Find the eigenvalues and eigenvectors of .
 Find a new coordinate system such that the matrix of components in the new coordinate system is a diagonal matrix.
 Identify the positive definite and semipositive definite symmetric matrices in the following:
 Find the missing values in the components of the orthogonal matrix so that it represents a change of basis while maintaining the proper orientation.
 Find the eigenvalues and eigenvectors of the following symmetric matrices and then perform the diagonalization process for each.
 The figure below shows a square with dimension . Determine the transformation matrix applied to the object to produce the image shown.
 Let , and be three vectors that are linearly independent. Using the properties of the dot product, construct an orthonormal basis set as a function of , and . (The construction is referred to as: GramSchmidt Process)
 Let . Find an example of a matrix such that . Then, show that if is a rotation matrix, then .
 Using Einstein summation convention, and assuming that the underlying space is the Euclidean space , show that the following relations hold true for the Kronecker Delta and the alternator :
 Write the following expressions out in full assuming that the underlying space is the Euclidean space :
 Write the following expressions in a compact form using index notation and the Einstein summation convention:

 .
 In the following expressions assume that

 Show that symmetric and antisymmetric matrices stay symmetric and antisymmetric, respectively, under any orthogonal coordinate transformation.
 Using the definitions of symmetric and antisymmetric tensors without reference to components.
 Using the component forms of symmetric and antisymmetric matrices.
 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.
 Show that if and are symmetric matrices, then is not necessarily a symmetric matrix. (Hint: Find a counter example). On the other hand, show that if and are symmetric matrices that have the same eigenvectors (also called “coaxial”), then and are symmetric.
 Show that if is a symmetric matrix, then , the matrix is symmetric.
 Let and is the identity matrix. Using the algebraic structure of matrices, show that if and , then . The matrix is referred to as the inverse of and is denoted .
 Let be a symmetric matrix. Let and be the minimum and maximum eigenvalues of . Show that . (The quantity is referred to as the Rayleigh Quotient)
 Let . Let be an invertible symmetric matrix. Show the following:
 is symmetric.
 Let be a symmetric matrix. Let be another matrix. Find the restriction on to ensure that the matrix is symmetric, i.e., that . (Hint: in a coordinate system of the eigenvectors of the ratios between the off diagonal components of is equal to the ratios between the corresponding eigenvalues of )

As will be discussed later, the stress at a point can be described as a symmetric matrix with the following form: