2020年3月27日金曜日

学習環境

解析入門 原書第3版 (S.ラング(著)、松坂 和夫(翻訳)、片山 孝次(翻訳)、岩波書店)の第Ⅵ部(多変数の関数)、第19章(多変数の関数)、1(グラフと等位線)の練習問題14の解答を求めてみる。


  1. x y x + y x - y = c x + y = c x - c y 1 + c y = c - 1 x y = c - 1 c + 1 x

    よって、 等位線は直線である。

コード

#!/usr/bin/env python3
from sympy import symbols, plot, solve, Rational
from sympy.plotting import plot3d

print('14.')

x, y, c = symbols('x, y, c', real=True)
eq = (x + y) / (x - y)
ys = solve(eq - c, y)
cs = [-10, -2, -Rational(1, 2), 0, Rational(1, 2), 1, 2, 10]
p = plot(*[ys[0].subs({c: c0}) for c0 in cs],
         (x, -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(p, colors):
    o.line_color = color

p.save('sample14.png')
for i, c0 in enumerate(cs):
    p = plot(*[f.subs({c: c0})
               for f in ys],
             (x, -10, 10),
             ylim=(-10, 10),
             legend=True,
             show=False)

    p.save(f'sample14_{i}.png')
p.show()

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

% ./sample14.py
14.
%

0 コメント:

コメントを投稿