2020年5月31日日曜日

学習環境

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


  1. 問1の点P、Q、A、Bについてのみ。

コード

#!/usr/bin/env python3
from sympy import symbols, Matrix
from sympy.plotting import plot_parametric
print('9.')

ps2 = [Matrix(p) for p in [(1, -1), (1, 4), (1, -1), (1, 4)]]
qs2 = [Matrix(q) for q in [(4, 3), (-3, 5), (4, 3), (-3, 5)]]
as2 = [Matrix(a) for a in [(-1, 5), (5, 7), (-1, 5), (5, 7)]]
bs2 = [Matrix(b) for b in [(5, 2), (1, 8), (7, 1), (9, 6)]]

t = symbols('t')
for i, p, q, a, b in zip([1, 2, 5, 6], ps2, qs2, as2, bs2):
    pp = plot_parametric((*(p + t * (q - p)), (t, 0, 1)),
                         (*(a + t * (b - a)), (t, 0, 1)),
                         (*(t * (q - p)), (t, 0, 1)),
                         (*(t * (b - a)), (t, 0, 1)),
                         xlim=(-10, 10),
                         ylim=(-10, 10),
                         legend=True,
                         show=False)
    colors = ['red', 'green', 'blue', 'brown', 'orange',
              'purple', 'pink', 'gray', 'skyblue', 'yellow']

    for o, color in zip(pp, colors):
        o.line_color = color
    pp.save(f'sample9_{i}.png')
pp.show()

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

% ./sample9.py
9.
/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)
%

0 コメント:

コメントを投稿