## 2018年9月5日水曜日

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

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

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

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

4. $\begin{array}{}\mathrm{det}\left(\begin{array}{ccc}x-5& 6& 6\\ 1& x-4& -2\\ -3& 6& x+4\end{array}\right)\\ =\left(x-5\right)\left(x-4\right)\left(x+4\right)+36+36-\left(-12\left(x-5\right)+6\left(x+4\right)-18\left(x-4\right)\right)\\ =\left(x-5\right)\left({x}^{2}-16\right)+72+12x-60-6x-24+18x-72\\ ={x}^{3}-5{x}^{2}+\left(-16+12-6+18\right)x-84+80\\ ={x}^{3}-5{x}^{2}+8x-4\\ =\left(x-1\right)\left({x}^{2}-4x+4\right)\\ =\left(x-1\right){\left(x-2\right)}^{2}\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 = [[[2, 4, 1],
[0, -1, - 3],
[0, 0, 0]],
[[0, 0, 1],
[1, 0, 0],
[0, 1, 0]],
[[1, 0, 0],
[-2, 2, -3],
[0, 3, 2]],
[[5, -6, -6],
[-1, 4, 2],
[3, -6, -4]]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