Table of Contents

In [22]:
import matplotlib.pyplot as plt
import numpy as np
from pprint import pprint

def draw_projcetion_line_points(x,y):
    p0 = np.array([x,y])
    p1 = np.dot(aa,p0)

    plt.plot(p0[0],p0[1],'o',color='r')
    plt.plot(p1[0],p1[1],'o',color='b')
    plt.plot([p0[0],p1[0]],[p0[1],p1[1]],
              color='k', linestyle='-', linewidth=1)

def draw_axes(x_min,x_max,y_min,y_max):
    plt.hlines(0, x_min, x_max, color='k', linestyle='-',
               linewidth=1)
    plt.vlines(0, y_min, y_max, color='k', linestyle='-',
               linewidth=1)

# aa = np.array([[2,5], [4,1]])
t = 0.1
aa = np.array([[np.cos(t),-np.sin(t)], [np.sin(t),np.cos(t)]])

pprint(aa)
array([[ 0.99500417, -0.09983342],
       [ 0.09983342,  0.99500417]])
In [23]:
div = 8 #32
for i in range(0,div):
    theta = 2*np.pi/div*i
    x0 = np.sin(theta)
    y0 = np.cos(theta)
    # print('%10.5f-%10.5f' % (x,y))
    draw_projcetion_line_points(x0,y0)

#draw_axes(-7,7,-5,5)
draw_axes(-1.5,1.5,-1.5,1.5)
plt.axes().set_aspect('equal', 'datalim')
plt.show()
In [24]:
np.set_printoptions(precision=3, suppress=True)

l,P = np.linalg.eig(aa)
pprint(l)
pprint(P)
array([ 0.995+0.1j,  0.995-0.1j])
array([[ 0.707+0.j   ,  0.707-0.j   ],
       [ 0.000-0.707j,  0.000+0.707j]])
In [25]:
v0 = P[:,0]
v1 = P[:,1]
pprint(v0)
pprint(v1)
array([ 0.707+0.j   ,  0.000-0.707j])
array([ 0.707-0.j   ,  0.000+0.707j])
In [26]:
def draw_eigen_vector(v, t):
    plt.plot([-t*v[0],t*v[0]], [-t*v[1],t*v[1]], 
             color='g', linestyle='-', linewidth=2)

div = 32
for i in range(0,div):
    theta = 2*np.pi/div*i
    x0 = np.sin(theta)
    y0 = np.cos(theta)
    # print('%10.5f-%10.5f' % (x,y))
    draw_projcetion_line_points(x0,y0)

draw_axes(-7,7,-5,5)

draw_eigen_vector(v0, 7)
draw_eigen_vector(v1, 5)

plt.axes().set_aspect('equal', 'datalim')
plt.show()
/Users/bob/anaconda3/lib/python3.6/site-packages/numpy/core/numeric.py:531: ComplexWarning: Casting complex values to real discards the imaginary part
  return array(a, dtype, copy=False, order=order)
In [ ]: