2020年5月16日土曜日

学習環境

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


  1. F [ 1 2 ] = [ cos π 4 - sin π 4 sin π 4 cos π 4 ] [ 1 2 ] = [ 1 2 - 1 2 1 2 1 2 ] [ 1 2 ] = [ - 1 2 3 2 ]

コード

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

print('4.')


class TestRotate(TestCase):
    def test(self):
        theta = pi / 4
        A = Matrix([[cos(theta), -sin(theta)],
                    [sin(theta), cos(theta)]])
        self.assertEqual(A * Matrix([1, 2]).reshape(2, 1),
                         Matrix([-1 / sqrt(2), 3 / sqrt(2)]).reshape(2, 1))


if __name__ == "__main__":
    main()

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

% ./sample4.py -v
4.
test (__main__.TestRotate) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.043s

OK
%

0 コメント:

コメントを投稿