数学のブログ

多変数の関数 グラフと等位線 放物線

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

2.
y - x 2 = c y = x 2 + c

等位線 は放物線。

3.

y - 3 x 2 = c y = 3 x 2 + c

等位線は放物線。

4.

x - y 2 = c x = y 2 + c

等位線は放物線。

コード

#!/usr/bin/env python3
from sympy import plot, solve
from sympy.abc import x, y, c

print('2、3、4.')

eqs = [y - x ** 2 - c,
       y - 3 * x ** 2 - c,
       x - y ** 2 - c]

p = plot(0,
         (x, -5, 5),
         ylim=(-5, 5),
         legend=True,
         show=False)
for eq in eqs:
    for c0 in range(-1, 2):
        ys = solve(eq.subs({c: c0}), y)
        ps = plot(*ys,
                  (x, -5, 5),
                  ylim=(-5, 5),
                  legend=True,
                  show=False)
        for o in ps:
            p.append(o)

colors = ['red', 'green', 'blue', 'brown', 'orange',
          'purple', 'pink', 'gray', 'skyblue', 'yellow']
for o, color in zip(p, colors):
    o.line_color = color
    print(o, color)
p.save('sample2.png')
p.show()

入出力結果

% ./sample2.py
2、3、4.
cartesian line: 0 for x over (-5.0, 5.0) red
cartesian line: x**2 - 1 for x over (-5.0, 5.0) green
cartesian line: x**2 for x over (-5.0, 5.0) blue
cartesian line: x**2 + 1 for x over (-5.0, 5.0) brown
cartesian line: 3*x**2 - 1 for x over (-5.0, 5.0) orange
cartesian line: 3*x**2 for x over (-5.0, 5.0) purple
cartesian line: 3*x**2 + 1 for x over (-5.0, 5.0) pink
cartesian line: -sqrt(x + 1) for x over (-5.0, 5.0) gray
cartesian line: sqrt(x + 1) for x over (-5.0, 5.0) skyblue
cartesian line: -sqrt(x) for x over (-5.0, 5.0) yellow
%