# 矩阵特征向量与特征值

linalg是linear algebra的缩写吧。

import numpy as np

A = np.random.rand(4, 4)
A
array([[0.14978175, 0.60689778, 0.02583363, 0.46816227],
[0.28508934, 0.74476942, 0.48711273, 0.75551799],
[0.54103663, 0.57551838, 0.16542061, 0.06687122],
[0.99511415, 0.07225251, 0.67671701, 0.80672535]])

$$\lambda (Lambda)$$

Lambda,W = np.linalg.eig(A)

Lambda
array([ 1.90910151+0.j        , -0.16902995+0.48364592j,
-0.16902995-0.48364592j,  0.29565552+0.j        ])
W
array([[-0.37740651+0.j        , -0.0403403 +0.46883807j,
-0.0403403 -0.46883807j,  0.17922515+0.j        ],
[-0.62172554+0.j        , -0.30567755+0.1341112j ,
-0.30567755-0.1341112j , -0.39087808+0.j        ],
[-0.34506145+0.j        ,  0.61011431+0.j        ,
0.61011431-0.j        , -0.67479126+0.j        ],
[-0.59325734+0.j        , -0.09427735-0.5348002j ,
-0.09427735+0.5348002j ,  0.59979116+0.j        ]])

$$\Sigma (Sigma)$$

Sigma = np.array(np.identity(4),dtype=complex)
for i in range(4):
Sigma[i,i] = Lambda[i]

Sigma
array([[ 1.90910151+0.j        ,  0.        +0.j        ,
0.        +0.j        ,  0.        +0.j        ],
[ 0.        +0.j        , -0.16902995+0.48364592j,
0.        +0.j        ,  0.        +0.j        ],
[ 0.        +0.j        ,  0.        +0.j        ,
-0.16902995-0.48364592j,  0.        +0.j        ],
[ 0.        +0.j        ,  0.        +0.j        ,
0.        +0.j        ,  0.29565552+0.j        ]])

$$W\Sigma W^{-1} = A$$

np.dot(np.dot(W,Sigma),np.linalg.inv(W))
array([[0.14732831+0.j, 0.41608559+0.j, 0.3469616 +0.j, 0.2353639 +0.j],
[0.94427989+0.j, 0.54550629+0.j, 0.4839118 +0.j, 0.67664038+0.j],
[0.83886785+0.j, 0.10101667+0.j, 0.0850258 +0.j, 0.65483286+0.j],
[0.73646205+0.j, 0.94155591+0.j, 0.92273078+0.j, 0.37602319+0.j]])

np.linalg.eig(A)
(array([ 2.04788686+0.j, -0.73295712+0.j, -0.1776856 +0.j,  0.01663945+0.j]),
array([[ 0.27874918-0.j, -0.21558825-0.j, -0.59281181+0.j,
-0.13927731+0.j],
[ 0.59156016-0.j,  0.23053778-0.j,  0.11428477+0.j,
-0.6623556 +0.j],
[ 0.36976417-0.j,  0.70290387+0.j, -0.1166957 +0.j,
0.70647971+0.j],
[ 0.66002268+0.j, -0.6374168 -0.j,  0.78860336+0.j,
0.20681712+0.j]]))

np.linalg.eig(3*A)
np.linalg.eig(3*A)

(array([ 6.14366059+0.j, -2.19887136+0.j, -0.53305679+0.j,  0.04991834+0.j]),
array([[ 0.27874918-0.j, -0.21558825-0.j, -0.59281181+0.j,
-0.13927731+0.j],
[ 0.59156016-0.j,  0.23053778-0.j,  0.11428477+0.j,
-0.6623556 +0.j],
[ 0.36976417-0.j,  0.70290387+0.j, -0.1166957 +0.j,
0.70647971+0.j],
[ 0.66002268+0.j, -0.6374168 -0.j,  0.78860336+0.j,
0.20681712+0.j]]))