2020年5月26日火曜日

学習環境

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


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

    グラフ。

コード

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

print('8.')

A = Matrix([2, -1])
B = Matrix([-1, 1])
cs = [2, 3, - 2, -3, Rational(1, 2)]
CS = [A + c * B for c in cs]
DS = [Matrix([x, y])
      for x, y in [(0, 1), (-1, 2), (4, -3), (5, -4),
                   (Rational(3, 2), -Rational(1, 2))]]


class TextVector(TestCase):
    def test(self):
        for C, D in zip(CS, DS):
            self.assertEqual(C, D)


t = symbols('t')
p = plot_parametric(*[(t * x, t * y, (t, 0, 1))
                      for x, y in DS],
                    *[(*(A + t * (C - A)), (t, 0, 1)) for C in CS],
                    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('sample8.png')

if __name__ == "__main__":
    main()

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

% ./sample8.py -v
8.
/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/sympy/plotting/plot.py:1065: MatplotlibDeprecationWarning: 
The set_smart_bounds function was deprecated in Matplotlib 3.2 and will be removed two minor releases later.
  self.ax[i].spines['left'].set_smart_bounds(True)
/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/sympy/plotting/plot.py:1066: MatplotlibDeprecationWarning: 
The set_smart_bounds function was deprecated in Matplotlib 3.2 and will be removed two minor releases later.
  self.ax[i].spines['bottom'].set_smart_bounds(False)
test (__main__.TextVector) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.001s

OK
%

0 コメント:

コメントを投稿