2019年12月24日火曜日

学習環境

解析入門 原書第3版 (S.ラング(著)、松坂 和夫(翻訳)、片山 孝次(翻訳)、岩波書店)の第Ⅵ部(多変数の関数)、第17章(ベクトル)、3(スカラー積)の練習問題1の解答を求めてみる。



    1. 2 , - 1 2 = 4 + 1 = 5

    2. - 1 , 3 2 = 1 + 9 = 10

    3. 2 , - 1 , 5 2 = 4 + 1 + 25 = 30

    4. - 1 , - 2 , 3 2 = 1 + 4 + 9 = 14

    5. π , 3 , - 1 = π 2 + 10

    6. 15 , - 2 , 4 2 = 225 + 4 + 16 = 245

コード

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

print('1.')

a = [(2, -1),
     (-1, 3),
     (2, -1, 5),
     (-1, -2, 3),
     (pi, 3, -1),
     (15, -2, 4)]


class MyTestCase(TestCase):
    def test(self):
        spam = [5, 10, 30, 14, pi ** 2 + 10, 245]
        for s, t in zip(a, spam):
            A = Matrix(s)
            self.assertEqual(A.dot(A), t)


if __name__ == '__main__':
    main()

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

% ./sample1.py -v
1.
test (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.040s

OK
%

0 コメント:

コメントを投稿