## 2018年11月2日金曜日

### 数学 - Python - 線型代数 - 行列の標準化 - 漸化式で定められる数列(再論)(長さ4の同次1次漸化式の一般項、固有多項式(特性多項式)、連立方程式の解、重解、複素数)

1. 固有多項式。

$\begin{array}{}f\left(x\right)\\ ={x}^{4}+2{x}^{2}+1\\ ={\left({x}^{2}+1\right)}^{2}\\ ={\left(x+i\right)}^{2}{\left(x-i\right)}^{2}\end{array}$

一般項は、 A、 B、 C、 D を定数として、

$\begin{array}{}{a}_{n}=A\left(\begin{array}{c}n\\ 0\end{array}\right){i}^{n}+B\left(\begin{array}{c}n\\ 1\end{array}\right){i}^{\left(n-1\right)}+C\left(\begin{array}{c}n\\ 0\end{array}\right){\left(-i\right)}^{n}+D\left(\begin{array}{c}n\\ 1\end{array}\right){\left(-i\right)}^{\left(n-1\right)}\\ =A{i}^{n}+nB{i}^{\left(n-1\right)}+C{\left(-i\right)}^{n}+nD{\left(-i\right)}^{\left(n-1\right)}\end{array}$

最初の4項より、

$\begin{array}{}{a}_{0}=A+C=0\\ {a}_{1}=Ai+B-Ci+D=1\\ {a}_{2}=-A+2Bi-C-2Di=2\\ {a}_{3}=-Ai-3B+Ci-3D=3\end{array}$

これを解く。

$\begin{array}{}C=-A\\ Ai+B+Ai+D=1\\ -A+2Bi+A-2Di=2\\ -Ai-3B-Ai-3D=3\\ 2Ai+B+D=1\\ Bi-Di=1\\ -2Ai-3B-3D=3\\ \left(B-D\right)i=1\\ B-D=-i\\ D=B+i\\ 2Ai+B+B+i=1\\ -2Ai-3B-3B-3i=3\\ 2Ai+2B=1-i\\ -2Ai-6B=3+3i\\ -4B=4+2i\\ B=-1-\frac{1}{2}i\\ 2Ai-2-i=1-i\\ 2Ai=3\\ A=-\frac{3}{2}i\\ D=-1-\frac{1}{2}i+i=-1+\frac{1}{2}i\\ C=\frac{3}{2}i\end{array}$

よって、求める一般項は、

$\begin{array}{}{a}_{n}=-\frac{3}{2}{i}^{\left(n+1\right)}+n\left(-1-\frac{1}{2}i\right){i}^{\left(n-1\right)}+\frac{3}{2}i{\left(-i\right)}^{n}+n\left(-1+\frac{1}{2}i\right){\left(-i\right)}^{n-1}\\ =\frac{3}{2}\left({\left(-1\right)}^{n}-1\right){i}^{\left(n+1\right)}+n\left(\left(-1-\frac{1}{2}i\right){i}^{n-1}+\left(-1+\frac{1}{2}i\right){\left(-1\right)}^{n-1}{i}^{n-1}\right)\\ =\frac{3}{2}\left({\left(-1\right)}^{n}-1\right){i}^{\left(n+1\right)}+n\left(-1-\frac{1}{2}i+{\left(-1\right)}^{n}+\frac{1}{2}{\left(-1\right)}^{n-1}i\right){i}^{n-1}\end{array}$

コード(Emacs)

Python 3

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

print('3.')

def a(n):
if n in set(range(4)):
return n
return -2 * a(n - 2) - a(n - 4)

n = symbols('n')
an = Rational(3, 2) * ((-1) ** n - 1) * I ** (n + 1) + \
n * (-1 - Rational(1, 2) * I + (-1) ** n +
Rational(1, 2) * (-1) ** (n - 1) * I) * I ** (n - 1)

for m in range(10):
t = a(m)
s = an.subs({n: m}).simplify()
print(f'n = {m}, {t}, {s}, {t == s}')


$./sample3.py 3. n = 0, 0, 0, True n = 1, 1, 1, True n = 2, 2, 2, True n = 3, 3, 3, True n = 4, -4, -4, True n = 5, -7, -7, True n = 6, 6, 6, True n = 7, 11, 11, True n = 8, -8, -8, True n = 9, -15, -15, True$