## 2018年1月13日土曜日

### 数学 - Python - 線形代数学 - 線形写像 – 線形写像(実数、3-空間、2-空間、射影、和、スカラー倍)

ラング線形代数学(上)(S.ラング (著)、芹沢 正三 (翻訳)、ちくま学芸文庫)の4章(線形写像)、2(線形写像)、練習問題12.を取り組んでみる。

1. $\begin{array}{}\left({x}_{1},{y}_{1},{z}_{1}\right),\left({x}_{2},{y}_{2},{z}_{2}\right)\in {\text{ℝ}}^{3}\\ a\in \text{ℝ}\end{array}$
$\begin{array}{}F\left(\left({x}_{1},{y}_{1},{z}_{1}\right)+\left({x}_{2},{y}_{2},{z}_{2}\right)\right)\\ =F\left(\left({x}_{1}+{x}_{2},{y}_{1}+{y}_{2},{z}_{1}+{z}_{2}\right)\right)\\ =\left({x}_{1}+{x}_{2},{y}_{1}+{y}_{2}\right)\\ =\left({x}_{1},{y}_{1}\right)+\left({x}_{2},{y}_{2}\right)\\ =F\left(\left({x}_{1},{y}_{1},{z}_{1}\right)\right)+F\left(\left({x}_{2},{y}_{2},{z}_{2}\right)\right)\end{array}$

2. $\begin{array}{}F\left(a\left({x}_{1},{y}_{1},{z}_{1}\right)\right)\\ =F\left(\left(a{x}_{1},a{y}_{1},a{z}_{1}\right)\right)\\ =\left(a{x}_{1},a{y}_{1}\right)\\ =a\left({x}_{1},{y}_{1}\right)\\ =aF\left(\left({x}_{1},{y}_{1},{z}_{1}\right)\right)\end{array}$

コード(Emacs)

Python 3

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

x1, y1, z1, x2, y2, z3, a = symbols('x1, y1, z1, x2, y2, z3, a')

def f(m):
return Matrix(m[:2])

v = Matrix([x1, y1, z1])
w = Matrix([x2, y2, z3])

for l, r in [(f(v + w), f(v) + f(w)),
(f(a * v), a * f(v))]:
for t in [l, r, l == r]:
pprint(t)
print()
print()


$./sample0.py ⎡x₁ + x₂⎤ ⎢ ⎥ ⎣y₁ + y₂⎦ ⎡x₁ + x₂⎤ ⎢ ⎥ ⎣y₁ + y₂⎦ True ⎡a⋅x₁⎤ ⎢ ⎥ ⎣a⋅y₁⎦ ⎡a⋅x₁⎤ ⎢ ⎥ ⎣a⋅y₁⎦ True$