## 2018年9月4日火曜日

### 数学 - Python - 線型代数 - 固有値と固有ベクトル - 固有多項式(特性多項式)(2次)

1. $\begin{array}{}\mathrm{det}\left(\begin{array}{cc}x+2& 1\\ -1& x-3\end{array}\right)\\ ={x}^{2}-x-6+1\\ ={x}^{2}-x-5\end{array}$

2. $\begin{array}{}\mathrm{det}\left(\begin{array}{cc}x-3& 1\\ -1& x-1\end{array}\right)\\ ={x}^{2}-4x+3+1\\ ={x}^{2}-4x+4\\ ={\left(x-2\right)}^{2}\end{array}$

3. $\begin{array}{}\mathrm{det}\left(\begin{array}{cc}x-1& -2\\ -2& x-4\end{array}\right)\\ ={x}^{2}-5x+4-4\\ =x\left(x-5\right)\end{array}$

4. $\begin{array}{}\mathrm{det}\left(\begin{array}{cc}x-5i& -1\\ -3& x-2i\end{array}\right)\\ ={x}^{2}-7ix-10-3\\ ={x}^{2}-7ix-13\end{array}$

コード(Emacs)

Python 3

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

print('5.')

x = symbols('x')

def g(i, j):
if i == j:
return 1
return 0

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

ms = [Matrix([[-2, -1],
[1, 3]]),
Matrix([[3, -1],
[1, 1]]),
Matrix([[1, 2],
[2, 4]]),
Matrix([[5 * I, 1],
[3, 2 * I]])]

for i, m in enumerate(ms):
print(f'({chr(ord("a") + i)})')
d = f(2, m).det()
for t in [m, f(2, m), d.expand(), d.simplify(), d.factor()]:
pprint(t)
print()
print()

$./sample5.py 5. (a) ⎡-2 -1⎤ ⎢ ⎥ ⎣1 3 ⎦ ⎡x + 2 1 ⎤ ⎢ ⎥ ⎣ -1 x - 3⎦ 2 x - x - 5 2 x - x - 5 2 x - x - 5 (b) ⎡3 -1⎤ ⎢ ⎥ ⎣1 1 ⎦ ⎡x - 3 1 ⎤ ⎢ ⎥ ⎣ -1 x - 1⎦ 2 x - 4⋅x + 4 (x - 3)⋅(x - 1) + 1 2 (x - 2) (c) ⎡1 2⎤ ⎢ ⎥ ⎣2 4⎦ ⎡x - 1 -2 ⎤ ⎢ ⎥ ⎣ -2 x - 4⎦ 2 x - 5⋅x x⋅(x - 5) x⋅(x - 5) (d) ⎡5⋅ⅈ 1 ⎤ ⎢ ⎥ ⎣ 3 2⋅ⅈ⎦ ⎡x - 5⋅ⅈ -1 ⎤ ⎢ ⎥ ⎣ -3 x - 2⋅ⅈ⎦ 2 x - 7⋅ⅈ⋅x - 13 2 x - 7⋅ⅈ⋅x - 13 2 x - 7⋅ⅈ⋅x - 13$