## 2020年6月12日金曜日

### 数学 - Pytyhon - 解析学 - ベクトル - ベクトルのノルム - 和と差のノルム、等式の証明、内積

1. $\begin{array}{l}{\parallel A+B\parallel }^{2}+{\parallel A-B\parallel }^{2}\\ =\left(A+B\right)·\left(A+B\right)+\left(A-B\right)·\left(A-B\right)\\ =A·A+A·B+B·A+B·B+A·A-A·B-B·A+B·B\\ ={\parallel A\parallel }^{2}+{\parallel B\parallel }^{2}\end{array}$

2. $\begin{array}{l}{\parallel A+B\parallel }^{2}\\ ={\parallel A\parallel }^{2}+A·B+A·B+{\parallel B\parallel }^{2}\\ ={\parallel A\parallel }^{2}+{\parallel B\parallel }^{2}+2A·B\end{array}$

3. $\begin{array}{l}{\parallel A+B\parallel }^{2}-{\parallel A-B\parallel }^{2}\\ =\left({\parallel A\parallel }^{2}+{\parallel B\parallel }^{2}+2A·B\right)-\left({\parallel A\parallel }^{2}+{\parallel B\parallel }^{2}-2A·B\right)\\ =4A·B\end{array}$

（証明終）

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import symbols, Matrix

print('8.')

class Test(TestCase):
def test(self):
a = Matrix(symbols('a:10', real=True))
b = Matrix(symbols('b:10', real=True))
for i, (s, t) in enumerate([
((a + b).norm() ** 2 + (a - b).norm() ** 2,
2 * a.norm() ** 2 + 2 * b.norm() ** 2),
((a + b).norm() ** 2,
a.norm() ** 2 + b.norm() ** 2 + 2 * a.dot(b)),
((a + b).norm() ** 2 - (a - b).norm() ** 2,
4 * a.dot(b))
]):
print(f'({chr(ord("a") + i)})')
self.assertEqual(s.expand(), t.expand())

if __name__ == "__main__":
main()


% ./sample8.py -v
8.
test (__main__.Test) ... (a)
(b)
(c)
ok

----------------------------------------------------------------------
Ran 1 test in 0.119s

OK
%