## 2020年1月5日日曜日

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

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

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

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

4. $\begin{array}{l}\frac{1-6-12}{1+4+9}\left(-1,-2,3\right)\\ =-\frac{17}{14}\left(-1,-2,3\right)\\ =\left(\frac{17}{14},\frac{17}{7},-\frac{51}{14}\right)\end{array}$

5. $\begin{array}{l}\frac{2{\pi }^{2}-9-7}{{\pi }^{2}+9+1}\left(\pi ,3,-1\right)\\ =\frac{2{\pi }^{2}-16}{{\pi }^{2}+10}\left(\pi ,3,-1\right)\end{array}$

6. $\begin{array}{l}\frac{15\pi -6-4}{225+4+16}\left(15,-2,4\right)\\ =\frac{15\pi -10}{245}\left(15,-2,4\right)\\ =\frac{3\pi -2}{49}\left(15,-2,4\right)\end{array}$

コード

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

print('4.')

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(6, 5), Rational(3, 5)),
(-Rational(6, 5), Rational(18, 5)),
(Rational(2, 15), -Rational(1, 15), Rational(1, 3)),
(Rational(17, 14), Rational(17, 7), -Rational(51, 14)),
[(2 * pi ** 2 - 16) / (pi ** 2 + 10) * x for x in [pi, 3, -1]],
[(3 * pi - 2) / 49 * x for x in [15, -2, 4]]]
for A, B, C in zip(As, Bs, egg):
A = Matrix(A)
B = Matrix(B)
C = Matrix(C)
self.assertTrue(eq(B.dot(A) / A.dot(A) * A, C))

if __name__ == '__main__':
main()


% ./sample4.py -v
4.
test (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.644s

OK
%