213 - A10.3 - Visual Eigensystems

1101 days ago by Professor213

John Travis

Mississippi College

Demonstrating the eigenvalue/eigenvector relationship in 2d and 3d

# 2x2 matrix and corresponding 2d view A = matrix(QQ,[[1, 8], [5, 4]]) D, V = A.eigenmatrix_right() lam = [D[0][0],D[1][1]] @interact def _(angle = slider(0,360,1,30),n = [0,1],Show_Eigenvector=checkbox(default=False)): pretty_print(html('In this interactive cell, for each of the two eigenvalues determine the corresponding eigenvector')) pretty_print(html('by finding the direction angle for which the resulting vector x satisfies $Ax = \lambda x$.')) pretty_print(html('The <font color="green">green</font> vector below corresponds to $\lambda x$ and the <font color="red">red</font> vector corresponds to $Ax$')) print ref_angle = (atan(V[1][n]/V[0][n])*180/pi).n(digits=3) print('Eigenvalue = '+str(lam[n])) if Show_Eigenvector: print('Eigenvector = '+ str(V[n])) print(ref_angle) show(A) angle = angle*pi/180 vec = [cos(angle).n(digits=3),sin(angle).n(digits=3)] pretty_print('Using the entered angle above yields the vector given by') show(vec) veclam = [lam[n]*cos(angle),lam[n]*sin(angle)] G = arrow((0,0),veclam,color='green',zorder=3) Ax = A*(vector(RR,[vec[0],vec[1]]).column()) Ax = (Ax[0][0],Ax[1][0]) G+= arrow((0,0),Ax,color='red',zorder=2) G.show(aspect_ratio=True,figsize=(4,6)) V*D == A*V 
       
angle 
Show_Eigenvector 
True

Click to the left again to hide and once more to show the dynamic interactive window

 
       
[  9  -4]
[  9 5/2]
[  9  -4]
[  9 5/2]
# 3x3 matrix and corresponding 3D view A = matrix(QQ,[[1, 6, 0], [3, 4, 0], [1, 1, 1]]) D, V = A.eigenmatrix_right() lam = [D[0][0],D[1][1],D[2][2]] @interact def _(theta = slider(0,360,1,30,label='$\\theta$ (rotation)'),phi = slider(0,180,1,30,label="$\\phi$ (elevation from N)"),n = [0,1,2]): pretty_print(html('In this interactive cell, for each of the two eigenvalues determine the corresponding eigenvector')) pretty_print(html('by finding the direction angle for which the resulting vector x satisfies $Ax = \lambda x$')) print("Eigenvalue = "+str(lam[n])) print("Eigenvector ="+str(V[n])) show(A) theta = theta*pi/180 phi = phi*pi/180 vec = [cos(theta)*sin(phi),sin(theta)*sin(phi),cos(phi)] # spherical coordinates veclam = [lam[n]*cos(theta)*sin(phi),lam[n]*sin(theta)*sin(phi),lam[n]*cos(phi)] G = arrow((0,0,0),veclam,color='green',zorder=3) Ax = A*(vector(RR,[vec[0],vec[1],vec[2]]).column()) Ax = (Ax[0][0],Ax[1][0],Ax[2][0]) G+= arrow((0,0,0),Ax,color='red',zorder=2) G.show(aspect_ratio=True,figsize=(4,6)) V*D == A*V 
       
$\theta$ (rotation) 
$\phi$ (elevation from N) 
True

Click to the left again to hide and once more to show the dynamic interactive window

# Notice that for a 2x2 matrix A with complex eigenvalues, a difference equation using any initial condition leads to oscillatory behavior @interact def _(mat = [1,2,3],n = input_box(width = 5,default=10)): if mat==1: A = matrix(QQ,[[4/5,3/5],[-3/5,4/5]]) # cycle elif mat==2: A = matrix(QQ,[[2/4,3/4],[-1/4,2/4]]) # spiral in else: A = matrix(QQ,[[4/4,3/4],[-3/4,4/4]]) # spiral out show(A) D, V = A.eigenmatrix_right() T = str(n)+" iterates using transition matrix with eigenvalues \n"+str(D[0][0])+" and \n"+str(D[1][1]) show(html(T)) show(V) x0 = vector(QQ,[1,-1]) Pts = [] Labs = [] Pts.append(x0) Labs = Graphics() for k in range(n): x0 = A*x0 Pts.append(x0) Labs += text(k+1,x0,aspect_ratio=1) show(graphics_array(((points(Pts,aspect_ratio=1),Labs)))) 
       
mat 

Click to the left again to hide and once more to show the dynamic interactive window