## 2018年9月2日日曜日

### 数学 - Python - 線型代数 - 固有値と固有ベクトル - 固有多項式(特性多項式)(正方行列、零、積)

1. $\begin{array}{}{f}_{A}\left(x\right)\\ =\mathrm{det}\left(x{I}_{n}-A\right)\\ =\mathrm{det}\left(\begin{array}{cc}x{I}_{r}-{A}_{1}& B\\ O& x{I}_{n-r}-{A}_{2}\end{array}\right)\\ =\mathrm{det}\left(x{I}_{r}-At\right)·\mathrm{det}\left(x{I}_{n-r}-{A}_{2}\right)\\ ={f}_{{A}_{1}}\left(x\right){f}_{{A}_{2}}\left(x\right)\end{array}$

B ではなく C の場合も同様。

コード(Emacs)

Python 3

#!/usr/bin/env python3
from sympy import pprint, symbols, Matrix, I, solve
import random

print('3.')

x = symbols('x')

def f(n, A):
def g(i, j):
if i == j:
return 1
return 0
In = Matrix([[g(i, j) for j in range(n)]
for i in range(n)])
return (x * In - A)

for _ in range(10):
n = random.randrange(2, 5)
r = random.randrange(1, n)
A1 = Matrix([[symbols(f'a{i + 1}{j + 1}') for j in range(r)]
for i in range(r)])
A2 = Matrix([[symbols(f'c{i + 1}{j + 1}') for j in range(n - r)]
for i in range(n - r)])
B = Matrix([[symbols(f'b{i + 1}{j + 1}') for j in range(n - r)]
for i in range(r)])

def h(i, j):
if i < r and j < r:
return A1[i, j]
if i < r and j >= r:
return B[i, j - r]
if j < r:
return 0
return A2[i - r, j - r]
A = Matrix([[h(i, j) for j in range(n)]
for i in range(n)])
fa = f(n, A)
fa1 = f(r, A1)
fa2 = f(n - r, A2)
for t in [A, fa.det().expand() == (fa1.det() * fa2.det()).expand()]:
pprint(t)
print()
print()
A1 = Matrix([[symbols(f'a{i + 1}{j + 1}') for j in range(r)]
for i in range(r)])
A2 = Matrix([[symbols(f'c{i + 1}{j + 1}') for j in range(n - r)]
for i in range(n - r)])
B = Matrix([[symbols(f'b{i + 1}{j + 1}') for j in range(r)]
for i in range(n - r)])

def h(i, j):
if i < r and j < r:
return A1[i, j]
if i < r and j >= r:
return 0
if j < r:
return B[i - r, j]
return A2[i - r, j - r]
A = Matrix([[h(i, j) for j in range(n)]
for i in range(n)])
fa = f(n, A)
fa1 = f(r, A1)
fa2 = f(n - r, A2)
for t in [A, fa.det().expand() == (fa1.det() * fa2.det()).expand()]:
pprint(t)
print()
print()


$./sample3.py 3. ⎡a₁₁ b₁₁ b₁₂⎤ ⎢ ⎥ ⎢ 0 c₁₁ c₁₂⎥ ⎢ ⎥ ⎣ 0 c₂₁ c₂₂⎦ True ⎡a₁₁ 0 0 ⎤ ⎢ ⎥ ⎢b₁₁ c₁₁ c₁₂⎥ ⎢ ⎥ ⎣b₂₁ c₂₁ c₂₂⎦ True ⎡a₁₁ a₁₂ a₁₃ b₁₁⎤ ⎢ ⎥ ⎢a₂₁ a₂₂ a₂₃ b₂₁⎥ ⎢ ⎥ ⎢a₃₁ a₃₂ a₃₃ b₃₁⎥ ⎢ ⎥ ⎣ 0 0 0 c₁₁⎦ True ⎡a₁₁ a₁₂ a₁₃ 0 ⎤ ⎢ ⎥ ⎢a₂₁ a₂₂ a₂₃ 0 ⎥ ⎢ ⎥ ⎢a₃₁ a₃₂ a₃₃ 0 ⎥ ⎢ ⎥ ⎣b₁₁ b₁₂ b₁₃ c₁₁⎦ True ⎡a₁₁ b₁₁⎤ ⎢ ⎥ ⎣ 0 c₁₁⎦ True ⎡a₁₁ 0 ⎤ ⎢ ⎥ ⎣b₁₁ c₁₁⎦ True ⎡a₁₁ a₁₂ b₁₁⎤ ⎢ ⎥ ⎢a₂₁ a₂₂ b₂₁⎥ ⎢ ⎥ ⎣ 0 0 c₁₁⎦ True ⎡a₁₁ a₁₂ 0 ⎤ ⎢ ⎥ ⎢a₂₁ a₂₂ 0 ⎥ ⎢ ⎥ ⎣b₁₁ b₁₂ c₁₁⎦ True ⎡a₁₁ a₁₂ b₁₁ b₁₂⎤ ⎢ ⎥ ⎢a₂₁ a₂₂ b₂₁ b₂₂⎥ ⎢ ⎥ ⎢ 0 0 c₁₁ c₁₂⎥ ⎢ ⎥ ⎣ 0 0 c₂₁ c₂₂⎦ True ⎡a₁₁ a₁₂ 0 0 ⎤ ⎢ ⎥ ⎢a₂₁ a₂₂ 0 0 ⎥ ⎢ ⎥ ⎢b₁₁ b₁₂ c₁₁ c₁₂⎥ ⎢ ⎥ ⎣b₂₁ b₂₂ c₂₁ c₂₂⎦ True ⎡a₁₁ a₁₂ a₁₃ b₁₁⎤ ⎢ ⎥ ⎢a₂₁ a₂₂ a₂₃ b₂₁⎥ ⎢ ⎥ ⎢a₃₁ a₃₂ a₃₃ b₃₁⎥ ⎢ ⎥ ⎣ 0 0 0 c₁₁⎦ True ⎡a₁₁ a₁₂ a₁₃ 0 ⎤ ⎢ ⎥ ⎢a₂₁ a₂₂ a₂₃ 0 ⎥ ⎢ ⎥ ⎢a₃₁ a₃₂ a₃₃ 0 ⎥ ⎢ ⎥ ⎣b₁₁ b₁₂ b₁₃ c₁₁⎦ True ⎡a₁₁ b₁₁⎤ ⎢ ⎥ ⎣ 0 c₁₁⎦ True ⎡a₁₁ 0 ⎤ ⎢ ⎥ ⎣b₁₁ c₁₁⎦ True ⎡a₁₁ b₁₁⎤ ⎢ ⎥ ⎣ 0 c₁₁⎦ True ⎡a₁₁ 0 ⎤ ⎢ ⎥ ⎣b₁₁ c₁₁⎦ True ⎡a₁₁ b₁₁ b₁₂⎤ ⎢ ⎥ ⎢ 0 c₁₁ c₁₂⎥ ⎢ ⎥ ⎣ 0 c₂₁ c₂₂⎦ True ⎡a₁₁ 0 0 ⎤ ⎢ ⎥ ⎢b₁₁ c₁₁ c₁₂⎥ ⎢ ⎥ ⎣b₂₁ c₂₁ c₂₂⎦ True ⎡a₁₁ a₁₂ b₁₁ b₁₂⎤ ⎢ ⎥ ⎢a₂₁ a₂₂ b₂₁ b₂₂⎥ ⎢ ⎥ ⎢ 0 0 c₁₁ c₁₂⎥ ⎢ ⎥ ⎣ 0 0 c₂₁ c₂₂⎦ True ⎡a₁₁ a₁₂ 0 0 ⎤ ⎢ ⎥ ⎢a₂₁ a₂₂ 0 0 ⎥ ⎢ ⎥ ⎢b₁₁ b₁₂ c₁₁ c₁₂⎥ ⎢ ⎥ ⎣b₂₁ b₂₂ c₂₁ c₂₂⎦ True$