## 2020年1月9日木曜日

### 数学 - Python - 解析学 - 多変数の関数 - ベクトル - ベクトルのノルム - n-空間、和のノルム、差のノルム、平方、関係式

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

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

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

コード

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

print('8.')

a = Matrix([1, 2, 3])
b = Matrix([-4, 5, -6])

class DistanceTestCase(TestCase):
def test_a(self):
self.assertEqual((a + b).norm() ** 2 + (a - b).norm()
** 2, 2 * a.norm() ** 2 + 2 * b.norm() ** 2)

def test_b(self):
self.assertEqual((a + b).norm() ** 2, a.norm() **
2 + b.norm() ** 2 + 2 * a.dot(b))

def test_c(self):
self.assertEqual((a + b).norm() ** 2 -
(a - b).norm() ** 2, 4 * a.dot(b))

if __name__ == '__main__':
main()


% ./sample8.py -v
8.
test_a (__main__.DistanceTestCase) ... ok
test_b (__main__.DistanceTestCase) ... ok
test_c (__main__.DistanceTestCase) ... ok

----------------------------------------------------------------------
Ran 3 tests in 0.045s

OK
%