2020年5月24日日曜日

学習環境

続 解析入門 (原書第2版) (S.ラング(著)、松坂 和夫(翻訳)、片山 孝次(翻訳)、岩波書店)の第1章(ベクトル)、1(空間の点の定義)の練習問題1の解答を求めてみる。



    1. A + B = 2 , - 1 + - 1 , 1 = 1 , 0 A - B = 2 , - 1 + 1 , - 1 = 3 , - 2 3 A = 6 , - 3 - 2 B = 2 , - 2

    2. A + B = - 1 , 7 A - B = - 1 , - 1 3 A = - 3 , 9 - 2 B = 0 , - 8

    3. A + B = 1 , 0 , 6 A - B = 3 , - 2 , 4 3 A = 6 , - 3 , 15 - 2 B = 2 , - 2 , - 2

    4. A + B = - 2 , 1 , - 1 A - B = 0 , - 5 , 7 3 A = - 3 , - 6 , 9 - 2 B = 2 , - 6 , 8

    5. A + B = 3 π , 0 , 6 A - B = - π , 6 , - 8 3 A = 3 π , 9 , - 3 - 2 B = - 4 π , 6 , - 14

    6. A + B = 15 + π , 1 , 3 A - B = 15 - π , - 5 , 5 3 A = 45 , - 6 , 12 - 2 B = - 2 π , - 6 , 2

問1の各点のグラフ 上の点。

問2の各点の グラフ上の点。

コード

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

print('1.')


class TextVector(TestCase):
    def test(self):
        AS = [[2, -1],
              [-1, 3],
              [2, -1, 5],
              [-1, -2, 3],
              [pi, 3, -1],
              [15, -2, 4]]
        BS = [[-1, 1],
              [0, 4],
              [-1, 1, 1],
              [-1, 3, -4],
              [2 * pi, -3, 7],
              [pi, 3, -1]]
        CS = [[1, 0],
              [-1, 7],
              [1, 0, 6],
              [-2, 1, -1],
              [3 * pi, 0, 6],
              [15 + pi, 1, 3]]
        DS = [[3, -2],
              [-1, -1],
              [3, -2, 4],
              [0, -5, 7],
              [-pi, 6, -8],
              [15 - pi, -5, 5]]
        ES = [[6, -3],
              [-3, 9],
              [6, -3, 15],
              [-3, -6, 9],
              [3 * pi, 9, -3],
              [45, -6, 12]]
        FS = [[2, -2],
              [0, -8],
              [2, -2, -2],
              [2, -6, 8],
              [-4 * pi, 6, -14],
              [-2 * pi, -6, 2]]
        for i, (A, B, C, D, E, F) in enumerate(zip(AS, BS, CS, DS, ES, FS), 1):
            print(f'({i})')
            A = Matrix(A)
            B = Matrix(B)
            self.assertEqual(A + B, Matrix(C))
            self.assertEqual(A - B, Matrix(D))
            self.assertEqual(3 * A, Matrix(E))
            self.assertEqual(-2 * B, Matrix(F))


t = symbols('t')
p = plot_parametric(*[(t * x, t * y, (t, 0, 1))
                      for x, y in [(2, -1), (-1, 1), (3, -2)]],
                    (2 + t, -1 - t, (t, 0, 1)),
                    xlim=(-5, 5),
                    ylim=(-5, 5),
                    legend=True,
                    show=False)
colors = ['red', 'green', 'blue', 'brown', 'orange',
          'purple', 'pink', 'gray', 'skyblue', 'yellow']

for o, color in zip(p, colors):
    o.line_color = color
p.show()
p.save('sample1.png')

if __name__ == "__main__":
    main()

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

% ./sample1.py -v
1.
test (__main__.TextVector) ... (1)
(2)
(3)
(4)
(5)
(6)
ok

----------------------------------------------------------------------
Ran 1 test in 0.004s

OK
%

0 コメント:

コメントを投稿