## 2020年3月24日火曜日

### 数学 - Python - 代数学 - 1次方程式, 2次方程式 - 2つの解、数列、漸化式、等式の証明

1. 問題の仮定より、

$\begin{array}{l}{\alpha }^{2}+p\alpha +q=0\\ {\alpha }^{n+2}+p{\alpha }^{n+1}+q{\alpha }^{n}=0\\ {\beta }^{2}+p\beta +q=0\\ {\beta }^{n+2}+p{\beta }^{n+1}+q{\beta }^{n}=0\\ \left({\alpha }^{n+2}+{\beta }^{n+2}\right)+p\left({\alpha }^{n+1}+{\beta }^{n+1}\right)+q\left({\alpha }^{n}+{\beta }^{n}\right)=0\\ {a}_{n+2}+p{a}_{n+1}+q{a}_{n}=0\end{array}$

（証明終）

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import symbols, solve, Rational, I

print('20.')

class MyTestCase(TestCase):
def test(self):
x = symbols('x')
p, q = symbols('p, q', real=True)
eq = x ** 2 + p * x + q
n = symbols('n', integer=True, positive=True)
alpha, beta = solve(eq, x)
an = alpha ** n + beta ** n
self.assertEqual(
(an.subs({n: n + 2}) + p *
an.subs({n: n + 1}) + q * an).simplify(),
0)

if __name__ == "__main__":
main()


% ./sample20.py -v
20.
test (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.526s

OK
%