## 2020年1月4日土曜日

### 数学 - Python - 解析学 - 多変数の関数 - ベクトル - ベクトルのノルム - 射影

1. $\begin{array}{l}\frac{-2-1}{1+1}\left(-1,1\right)\\ =-\frac{3}{2}\left(-1,1\right)\\ =\left(\frac{3}{2},-\frac{3}{2}\right)\end{array}$

2. $\begin{array}{l}\frac{12}{16}\left(0,4\right)\\ =\left(0,3\right)\end{array}$

3. $\begin{array}{l}\frac{-2-1+5}{1+1+1}\left(-1,1,1\right)\\ =\left(-\frac{2}{3},\frac{2}{3},\frac{2}{3}\right)\end{array}$

4. $\begin{array}{l}\frac{1-6-12}{1+9+16}\left(-1,3,-4\right)\\ =-\frac{17}{26}\left(-1,3,-4\right)\\ =\left(\frac{17}{26},-\frac{51}{26},\frac{34}{13}\right)\end{array}$

5. $\begin{array}{l}\frac{2{\pi }^{2}-9-7}{4{\pi }^{2}+9+49}\left(2\pi ,-3,7\right)\\ =\frac{2{\pi }^{2}-16}{4{\pi }^{2}+58}\left(2\pi ,-3,7\right)\\ =\frac{{\pi }^{2}-8}{2{\pi }^{2}+29}\left(2\pi ,-3,7\right)\\ =\left(\frac{2{\pi }^{3}-16\pi }{2{\pi }^{2}+29},\frac{-3{\pi }^{2}+24}{2{\pi }^{2}+29},\frac{7{\pi }^{2}-56}{2{\pi }^{2}+29}\right)\end{array}$

6. $\begin{array}{l}\frac{15\pi -6-4}{{\pi }^{2}+9+1}\left(\pi ,3,-1\right)\\ =\frac{15\pi -10}{{\pi }^{2}+10}\left(\pi ,3,-1\right)\\ =\left(\frac{15{\pi }^{2}-10\pi }{{\pi }^{2}+10},\frac{45\pi -30}{{\pi }^{2}+10},\frac{-15\pi +10}{{\pi }^{2}+10}\right)\end{array}$

コード

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

print('3.')

def eq(A, B):
for a, b in zip(A, B):
if a.simplify() != b.simplify():
return False
return True

class MyTestCase(TestCase):
def test(self):
As = [(2, -1),
(-1, 3),
(2, -1, 5),
(-1, -2, 3),
(pi, 3, -1),
(15, -2, 4)]
Bs = [(-1, 1),
(0, 4),
(-1, 1, 1),
(-1, 3, -4),
(2 * pi, -3, 7),
(pi, 3, -1)]
egg = [(Rational(3, 2), -Rational(3, 2)),
(0, 3),
(-Rational(2, 3), Rational(2, 3), Rational(2, 3)),
(Rational(17, 26), -Rational(51, 26), Rational(34, 13)),
((2 * pi ** 3 - 16 * pi) / (2 * pi ** 2 + 29), (-3 * pi ** 2 + 24) /
(2 * pi ** 2 + 29), (7 * pi ** 2 - 56) / (2 * pi ** 2 + 29)),
((15 * pi ** 2 - 10 * pi) / (pi ** 2 + 10), (45 * pi - 30) /
(pi ** 2 + 10), (-15 * pi + 10) / (pi ** 2 + 10))]
for A, B, C in zip(As, Bs, egg):
A = Matrix(A)
B = Matrix(B)
C = Matrix(C)
self.assertTrue(eq(A.dot(B) / B.dot(B) * B, C))

if __name__ == '__main__':
main()


% ./sample3.py -v
3.
test (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.878s

OK
%