2020年5月18日月曜日

学習環境

ラング線形代数学(上) (ちくま学現文庫)(S.ラング (著)、芹沢 正三 (翻訳)、筑摩書房)の5章(線形写像と行列)、2(線形写像に対応する行列)、練習問題6の解答を求めてみる。


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

    よって、

    x ' = x cos θ + y sin θ y ' = - x sin θ + y cos θ

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import symbols, Matrix, cos, sin, solve

print('6.')


class TestRotate(TestCase):
    def test(self):
        theta = symbols('θ')
        A = Matrix([[cos(theta), sin(theta)],
                    [-sin(theta), cos(theta)]])
        x0, x1 = symbols('x:2')
        y0, y1 = symbols('y:2')
        X0 = Matrix([x0, y0]).reshape(2, 1)
        X1 = Matrix([x1, y1]).reshape(2, 1)
        self.assertEqual(solve(A * X0 - X1, x1, y1),
                         {x1: x0 * cos(theta) + y0 * sin(theta),
                          y1: -x0 * sin(theta) + y0 * cos(theta)})


if __name__ == "__main__":
    main()

入出力結果(Zsh、PowerShell、Terminal、Jupyter(IPython))

% ./sample6.py -v
6.
test (__main__.TestRotate) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.364s

OK
%

0 コメント:

コメントを投稿