数学のブログ

多変数の関数 グラフと等位線 円、双曲線

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

問5

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

等位線は円。

問6

x y = c

c が0の場合、 x 軸または y 軸。

c 0

の場合。

y = c x

双曲線。

問7

( x - 1 ) ( y - 2 ) = c
c = 0 x = 1 y = 2
c 0 y = c x - 1 + 2

問8

( x + 1 ) ( y + 3 ) = c
c = 0 x = - 1 y = - 3
c 0 y = c x + 1 - 3

コード

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

print('5, 6, 7, 8.')

fs = [3 * x ** 2 + 3 * y ** 2,
      x * y,
      (x - 1) * (y - 2),
      (x + 1) * (y + 3)]
colors = ['red', 'green', 'blue', 'brown', 'orange',
          'purple', 'pink', 'gray', 'skyblue', 'yellow']

for i, f in enumerate(fs, 5):
    print(f'{i}.')
    p = plot3d(f, show=False)
    p.save(f'sample{i}_1.png')
    ys = []
    for c in range(-5, 5):
        ys += solve(f - c, y)
    p = plot(*ys,
             (x, -10, 10),
             ylim=(-10, 10),
             legend=True,
             show=False)
    for o, color in zip(p, colors):
        o.line_color = color
        print(o, color)
    p.save(f'sample{i}_2.png')

p.show()

入出力結果

% ./sample5.py
5, 6, 7, 8.
5.
cartesian line: -sqrt(-9*x**2 - 15)/3 for x over (-10.0, 10.0) red
cartesian line: sqrt(-9*x**2 - 15)/3 for x over (-10.0, 10.0) green
cartesian line: -sqrt(-9*x**2 - 12)/3 for x over (-10.0, 10.0) blue
cartesian line: sqrt(-9*x**2 - 12)/3 for x over (-10.0, 10.0) brown
cartesian line: -sqrt(-x**2 - 1) for x over (-10.0, 10.0) orange
cartesian line: sqrt(-x**2 - 1) for x over (-10.0, 10.0) purple
cartesian line: -sqrt(-9*x**2 - 6)/3 for x over (-10.0, 10.0) pink
cartesian line: sqrt(-9*x**2 - 6)/3 for x over (-10.0, 10.0) gray
cartesian line: -sqrt(-9*x**2 - 3)/3 for x over (-10.0, 10.0) skyblue
cartesian line: sqrt(-9*x**2 - 3)/3 for x over (-10.0, 10.0) yellow
6.
cartesian line: -5/x for x over (-10.0, 10.0) red
cartesian line: -4/x for x over (-10.0, 10.0) green
cartesian line: -3/x for x over (-10.0, 10.0) blue
cartesian line: -2/x for x over (-10.0, 10.0) brown
cartesian line: -1/x for x over (-10.0, 10.0) orange
cartesian line: 0 for x over (-10.0, 10.0) purple
cartesian line: 1/x for x over (-10.0, 10.0) pink
cartesian line: 2/x for x over (-10.0, 10.0) gray
cartesian line: 3/x for x over (-10.0, 10.0) skyblue
cartesian line: 4/x for x over (-10.0, 10.0) yellow
7.
cartesian line: (2*x - 7)/(x - 1) for x over (-10.0, 10.0) red
cartesian line: 2*(x - 3)/(x - 1) for x over (-10.0, 10.0) green
cartesian line: (2*x - 5)/(x - 1) for x over (-10.0, 10.0) blue
cartesian line: 2*(x - 2)/(x - 1) for x over (-10.0, 10.0) brown
cartesian line: (2*x - 3)/(x - 1) for x over (-10.0, 10.0) orange
cartesian line: 2 for x over (-10.0, 10.0) purple
cartesian line: (2*x - 1)/(x - 1) for x over (-10.0, 10.0) pink
cartesian line: 2*x/(x - 1) for x over (-10.0, 10.0) gray
cartesian line: (2*x + 1)/(x - 1) for x over (-10.0, 10.0) skyblue
cartesian line: 2*(x + 1)/(x - 1) for x over (-10.0, 10.0) yellow
8.
cartesian line: -(3*x + 8)/(x + 1) for x over (-10.0, 10.0) red
cartesian line: -(3*x + 7)/(x + 1) for x over (-10.0, 10.0) green
cartesian line: -(3*x + 6)/(x + 1) for x over (-10.0, 10.0) blue
cartesian line: -(3*x + 5)/(x + 1) for x over (-10.0, 10.0) brown
cartesian line: -(3*x + 4)/(x + 1) for x over (-10.0, 10.0) orange
cartesian line: -3 for x over (-10.0, 10.0) purple
cartesian line: -(3*x + 2)/(x + 1) for x over (-10.0, 10.0) pink
cartesian line: -(3*x + 1)/(x + 1) for x over (-10.0, 10.0) gray
cartesian line: -3*x/(x + 1) for x over (-10.0, 10.0) skyblue
cartesian line: (1 - 3*x)/(x + 1) for x over (-10.0, 10.0) yellow
%