## 2018年11月1日木曜日

### 数学 - Python - JavaScript - 線形代数学 - R^n におけるベクトル – ベクトルのノルム(射影2)

ラング線形代数学(上)(S.ラング (著)、芹沢 正三 (翻訳)、ちくま学芸文庫)の1章(R^n におけるベクトル)、3(ベクトルのノルム)、練習問題4.を取り組んでみる。

1. $\frac{-3}{4+1}\left(2,-1\right)=-\frac{3}{5}\left(2,-1\right)$

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

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

4. $\frac{1-6-12}{1+4+9}\left(-1,-2,3\right)=-\frac{19}{14}\left(-1,-2,3\right)$

5. $\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)$

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

コード(Emacs)

Python 3

#!/usr/bin/env python3
from sympy import pprint, symbols, Matrix, pi

print('4.')

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)]

for i, (a, b) in enumerate(zip(As, Bs), 1):
print(f'(i)')
A = Matrix(a)
B = Matrix(b)
pprint((A.dot(B) / A.dot(A) * A).T)
print()


コード(Emacs)

Python 3

#!/usr/bin/env python3
from sympy import pprint, symbols, Matrix, pi

print('4.')

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)]

for i, (a, b) in enumerate(zip(As, Bs), 1):
print(f'({i})')
A = Matrix(a)
B = Matrix(b)
pprint((A.dot(B) / A.dot(A) * A).T)
print()


$./sample4.py 4. (1) [-6/5 3/5] (2) [-6/5 18/5] (3) [2/15 -1/15 1/3] (4) ⎡17 -51 ⎤ ⎢── 17/7 ────⎥ ⎣14 14 ⎦ (5) ⎡ ⎛ 2⎞ ⎛ 2⎞ ⎛ 2⎞ ⎤ ⎢π⋅⎝-16 + 2⋅π ⎠ 3⋅⎝-16 + 2⋅π ⎠ -⎝-16 + 2⋅π ⎠ ⎥ ⎢────────────── ────────────── ──────────────⎥ ⎢ 2 2 2 ⎥ ⎣ π + 10 π + 10 π + 10 ⎦ (6) ⎡ 30 45⋅π 6⋅π 4 8 12⋅π⎤ ⎢- ── + ──── - ─── + ── - ── + ────⎥ ⎣ 49 49 49 49 49 49 ⎦$