## 2019年5月12日日曜日

### 数学 - Python - 線形代数学 - 線形写像と行列 - 線形写像の合成(行列写像、逆写像、三角関数(正弦と余弦、加法定理))

ラング線形代数学(上)(S.ラング (著)、芹沢 正三 (翻訳)、ちくま学芸文庫)の4章(線形写像と行列)、3(線形写像の合成)、練習問題1の解答を求めてみる。

1. $\begin{array}{l}\left[\begin{array}{cc}\mathrm{cos}\theta & -\mathrm{sin}\theta \\ \mathrm{sin}\theta & \mathrm{cos}\theta \end{array}\right]\left[\begin{array}{cc}\mathrm{cos}\theta \text{'}& -\mathrm{sin}\theta \text{'}\\ \mathrm{sin}\theta \text{'}& \mathrm{cos}\theta \text{'}\end{array}\right]\\ =\left[\begin{array}{cc}\mathrm{cos}\theta \mathrm{cos}\theta \text{'}-\mathrm{sin}\theta \mathrm{sin}\theta \text{'}& -\mathrm{sin}\theta \mathrm{cos}\theta \text{'}-\mathrm{cos}\theta \mathrm{sin}\theta \text{'}\\ \mathrm{sin}\theta \mathrm{cos}\theta \text{'}+\mathrm{cos}\theta \mathrm{sin}\theta \text{'}& \mathrm{cos}\theta \mathrm{cos}\theta \text{'}-\mathrm{sin}\theta \mathrm{sin}\theta \text{'}\end{array}\right]\\ =\left[\begin{array}{cc}\mathrm{cos}\left(\theta +\theta \text{'}\right)& -\mathrm{sin}\left(\theta +\theta \text{'}\right)\\ \mathrm{sin}\left(\theta +\theta \text{'}\right)& \mathrm{cos}\left(\theta -\theta \text{'}\right)\end{array}\right]\end{array}$

また、逆写像について、

$\begin{array}{l}\left[\begin{array}{cc}\mathrm{cos}\theta & -\mathrm{sin}\theta \\ \mathrm{sin}\theta & \mathrm{cos}\theta \end{array}\right]\left[\begin{array}{cc}\mathrm{cos}\left(-\theta \right)& -\mathrm{sin}\left(-\theta \right)\\ \mathrm{sin}\left(-\theta \right)& \mathrm{cos}\left(-\theta \right)\end{array}\right]\\ =\left[\begin{array}{cc}\mathrm{cos}\theta & -\mathrm{sin}\theta \\ \mathrm{sin}\theta & \mathrm{cos}\theta \end{array}\right]\left[\begin{array}{cc}\mathrm{cos}\theta & \mathrm{sin}\theta \\ -\mathrm{sin}\theta & \mathrm{cos}\theta \end{array}\right]\\ =\left[\begin{array}{cc}{\mathrm{cos}}^{2}\theta +{\mathrm{sin}}^{2}\theta & \mathrm{sin}\theta \mathrm{cos}\theta -\mathrm{sin}\theta \mathrm{cos}\theta \\ \mathrm{sin}\theta \mathrm{cos}\theta -\mathrm{sin}\theta \mathrm{cos}\theta & {\mathrm{sin}}^{2}\theta +{\mathrm{cos}}^{2}\theta \end{array}\right]\\ =\left[\begin{array}{cc}1& 0\\ 0& 1\end{array}\right]\end{array}$

コード

Python 3

#!/usr/bin/env python3
from sympy import pprint, sin, cos, pi, symbols, Matrix
import random
print('1.')

def is_equal(a, b):
for a0, b0 in zip(a, b):
if abs(a0 - b0) > 0.00001:
return False
return True

theta = symbols('θ')
m = Matrix([[cos(theta), -sin(theta)],
[sin(theta), cos(theta)]])

for _ in range(1):
alpha = random.random() * 5
beta = random.random() * 5
a = m.subs({theta: alpha})
b = m.subs({theta: beta})
c = m.subs({theta: alpha + beta})
d = m.subs({theta: -alpha})
for o in [a * b,  c, a * b == c, is_equal(a * b, c),
a ** -1, d, a ** -1 == b, is_equal(a ** -1, d)]:
pprint(o)
print()


C:\Users\...>py sample1.py
1.
⎡0.333157837639125  -0.942871070305809⎤
⎢                                     ⎥
⎣0.942871070305809  0.333157837639125 ⎦

⎡0.333157837639125  -0.94287107030581⎤
⎢                                    ⎥
⎣0.94287107030581   0.333157837639125⎦

False

True

⎡-0.991185474314604  0.132481528930389 ⎤
⎢                                      ⎥
⎣-0.132481528930389  -0.991185474314604⎦

⎡-0.991185474314604  0.132481528930389 ⎤
⎢                                      ⎥
⎣-0.132481528930389  -0.991185474314604⎦

False

True

⎡0.960155657655813  -0.279465763684091⎤
⎢                                     ⎥
⎣0.279465763684091  0.960155657655813 ⎦

⎡0.960155657655813  -0.279465763684091⎤
⎢                                     ⎥
⎣0.279465763684091  0.960155657655813 ⎦

False

True

⎡-0.972630495633886  0.232357308821954 ⎤
⎢                                      ⎥
⎣-0.232357308821954  -0.972630495633886⎦

⎡-0.972630495633886  0.232357308821954 ⎤
⎢                                      ⎥
⎣-0.232357308821954  -0.972630495633886⎦

False

True

⎡-0.435322163309999  0.900274743692781 ⎤
⎢                                      ⎥
⎣-0.900274743692781  -0.435322163309999⎦

⎡-0.435322163309999  0.900274743692781 ⎤
⎢                                      ⎥
⎣-0.900274743692781  -0.435322163309999⎦

False

True

⎡0.959312956308071   0.282344916475343⎤
⎢                                     ⎥
⎣-0.282344916475343  0.959312956308072⎦

⎡0.959312956308071   0.282344916475343⎤
⎢                                     ⎥
⎣-0.282344916475343  0.959312956308071⎦

False

True

⎡0.478845051813146  -0.877899434077768⎤
⎢                                     ⎥
⎣0.877899434077768  0.478845051813146 ⎦

⎡0.478845051813146  -0.877899434077768⎤
⎢                                     ⎥
⎣0.877899434077768  0.478845051813146 ⎦

False

True

⎡-0.850017242827261   0.52675486414113 ⎤
⎢                                      ⎥
⎣-0.52675486414113   -0.850017242827261⎦

⎡-0.850017242827261   0.52675486414113 ⎤
⎢                                      ⎥
⎣-0.52675486414113   -0.850017242827261⎦

False

True

⎡-0.698831727148813  -0.715286108581879⎤
⎢                                      ⎥
⎣0.715286108581879   -0.698831727148813⎦

⎡-0.698831727148813  -0.715286108581879⎤
⎢                                      ⎥
⎣0.715286108581879   -0.698831727148813⎦

False

True

⎡-0.138743701806266  -0.990328321926165⎤
⎢                                      ⎥
⎣0.990328321926165   -0.138743701806266⎦

⎡-0.138743701806266  -0.990328321926165⎤
⎢                                      ⎥
⎣0.990328321926165   -0.138743701806266⎦

False

True

C:\Users\...>