2019年5月12日日曜日

学習環境

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


  1. [ cos θ - sin θ sin θ cos θ ] [ cos θ ' - sin θ ' sin θ ' cos θ ' ] = [ cos θ cos θ ' - sin θ sin θ ' - sin θ cos θ ' - cos θ sin θ ' sin θ cos θ ' + cos θ sin θ ' cos θ cos θ ' - sin θ sin θ ' ] = [ cos θ + θ ' - sin θ + θ ' sin θ + θ ' cos θ - θ ' ]

    また、逆写像について、

    [ cos θ - sin θ sin θ cos θ ] [ cos - θ - sin - θ sin - θ cos - θ ] = [ cos θ - sin θ sin θ cos θ ] [ cos θ sin θ - sin θ cos θ ] = [ cos 2 θ + sin 2 θ sin θ cos θ - sin θ cos θ sin θ cos θ - sin θ cos θ sin 2 θ + cos 2 θ ] = [ 1 0 0 1 ]

コード

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

入出力結果(cmd(コマンドプロンプト)、Terminal、Jupyter(IPython))

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\...>

0 コメント:

コメントを投稿