多変数の関数 グラフと等位線 点、円、双曲線
続 解析入門 (原書第2版) (S.ラング(著)、松坂 和夫(翻訳)、片山 孝次(翻訳)、岩波書店)の第3章(多変数の関数)、1(グラフと等位線)の練習問題18、19、20.の解答を求めてみる。
18
19
20
コード
#!/usr/bin/env python3
from sympy import plot, solve
from sympy.plotting import plot3d
from sympy.abc import x, y
print('18、19、20.')
fs = [(x - 1) ** 2 + (y + 3) ** 2,
x ** 2 - y ** 2,
(x + 1) ** 2 + y ** 2]
colors = ['red', 'green', 'blue', 'brown', 'orange',
'purple', 'pink', 'gray', 'skyblue', 'yellow']
for i, f in enumerate(fs, 18):
print(f'({i})')
p = plot3d(f, show=False)
p.save(f'sample{i}_1.png')
ys = []
for c in range(-5, 6):
ys += solve(f - c, y)
print(ys)
p = plot(*ys,
(x, -10, 10),
ylim=(-10, 10),
legend=False,
show=False,
xlabel=x,
ylabel=y)
for o, color in zip(p, colors * 2):
o.line_color = color
print(o, color)
p.xlabel = x
p.ylabel = y
p.save(f'sample{i}_2.png')
p.show()
入出力結果
% ./sample18.py
18、19、20.
(18)
[-sqrt(-x**2 + 2*x - 6) - 3, sqrt(-x**2 + 2*x - 6) - 3, -sqrt(-x**2 + 2*x - 5) - 3, sqrt(-x**2 + 2*x - 5) - 3, -sqrt(-x**2 + 2*x - 4) - 3, sqrt(-x**2 + 2*x - 4) - 3, -sqrt(-x**2 + 2*x - 3) - 3, sqrt(-x**2 + 2*x - 3) - 3, -sqrt(-x**2 + 2*x - 2) - 3, sqrt(-x**2 + 2*x - 2) - 3, I*(1 - x) - 3, I*(x - 1) - 3, sqrt(x*(2 - x)) - 3, -sqrt(-x*(x - 2)) - 3, -sqrt(-x**2 + 2*x + 1) - 3, sqrt(-x**2 + 2*x + 1) - 3, -sqrt(-x**2 + 2*x + 2) - 3, sqrt(-x**2 + 2*x + 2) - 3, -sqrt(-(x - 3)*(x + 1)) - 3, sqrt(-(x - 3)*(x + 1)) - 3, -sqrt(-x**2 + 2*x + 4) - 3, sqrt(-x**2 + 2*x + 4) - 3]
cartesian line: -sqrt(-x**2 + 2*x - 6) - 3 for x over (-10.0, 10.0) red
cartesian line: sqrt(-x**2 + 2*x - 6) - 3 for x over (-10.0, 10.0) green
cartesian line: -sqrt(-x**2 + 2*x - 5) - 3 for x over (-10.0, 10.0) blue
cartesian line: sqrt(-x**2 + 2*x - 5) - 3 for x over (-10.0, 10.0) brown
cartesian line: -sqrt(-x**2 + 2*x - 4) - 3 for x over (-10.0, 10.0) orange
cartesian line: sqrt(-x**2 + 2*x - 4) - 3 for x over (-10.0, 10.0) purple
cartesian line: -sqrt(-x**2 + 2*x - 3) - 3 for x over (-10.0, 10.0) pink
cartesian line: sqrt(-x**2 + 2*x - 3) - 3 for x over (-10.0, 10.0) gray
cartesian line: -sqrt(-x**2 + 2*x - 2) - 3 for x over (-10.0, 10.0) skyblue
cartesian line: sqrt(-x**2 + 2*x - 2) - 3 for x over (-10.0, 10.0) yellow
cartesian line: I*(1 - x) - 3 for x over (-10.0, 10.0) red
cartesian line: I*(x - 1) - 3 for x over (-10.0, 10.0) green
cartesian line: sqrt(x*(2 - x)) - 3 for x over (-10.0, 10.0) blue
cartesian line: -sqrt(-x*(x - 2)) - 3 for x over (-10.0, 10.0) brown
cartesian line: -sqrt(-x**2 + 2*x + 1) - 3 for x over (-10.0, 10.0) orange
cartesian line: sqrt(-x**2 + 2*x + 1) - 3 for x over (-10.0, 10.0) purple
cartesian line: -sqrt(-x**2 + 2*x + 2) - 3 for x over (-10.0, 10.0) pink
cartesian line: sqrt(-x**2 + 2*x + 2) - 3 for x over (-10.0, 10.0) gray
cartesian line: -sqrt(-(x - 3)*(x + 1)) - 3 for x over (-10.0, 10.0) skyblue
cartesian line: sqrt(-(x - 3)*(x + 1)) - 3 for x over (-10.0, 10.0) yellow
(19)
[-sqrt(x**2 + 5), sqrt(x**2 + 5), -sqrt(x**2 + 4), sqrt(x**2 + 4), -sqrt(x**2 + 3), sqrt(x**2 + 3), -sqrt(x**2 + 2), sqrt(x**2 + 2), -sqrt(x**2 + 1), sqrt(x**2 + 1), -x, x, -sqrt(x**2 - 1), sqrt(x**2 - 1), -sqrt(x**2 - 2), sqrt(x**2 - 2), -sqrt(x**2 - 3), sqrt(x**2 - 3), -sqrt(x**2 - 4), sqrt(x**2 - 4), -sqrt(x**2 - 5), sqrt(x**2 - 5)]
cartesian line: -sqrt(x**2 + 5) for x over (-10.0, 10.0) red
cartesian line: sqrt(x**2 + 5) for x over (-10.0, 10.0) green
cartesian line: -sqrt(x**2 + 4) for x over (-10.0, 10.0) blue
cartesian line: sqrt(x**2 + 4) for x over (-10.0, 10.0) brown
cartesian line: -sqrt(x**2 + 3) for x over (-10.0, 10.0) orange
cartesian line: sqrt(x**2 + 3) for x over (-10.0, 10.0) purple
cartesian line: -sqrt(x**2 + 2) for x over (-10.0, 10.0) pink
cartesian line: sqrt(x**2 + 2) for x over (-10.0, 10.0) gray
cartesian line: -sqrt(x**2 + 1) for x over (-10.0, 10.0) skyblue
cartesian line: sqrt(x**2 + 1) for x over (-10.0, 10.0) yellow
cartesian line: -x for x over (-10.0, 10.0) red
cartesian line: x for x over (-10.0, 10.0) green
cartesian line: -sqrt(x**2 - 1) for x over (-10.0, 10.0) blue
cartesian line: sqrt(x**2 - 1) for x over (-10.0, 10.0) brown
cartesian line: -sqrt(x**2 - 2) for x over (-10.0, 10.0) orange
cartesian line: sqrt(x**2 - 2) for x over (-10.0, 10.0) purple
cartesian line: -sqrt(x**2 - 3) for x over (-10.0, 10.0) pink
cartesian line: sqrt(x**2 - 3) for x over (-10.0, 10.0) gray
cartesian line: -sqrt(x**2 - 4) for x over (-10.0, 10.0) skyblue
cartesian line: sqrt(x**2 - 4) for x over (-10.0, 10.0) yellow
(20)
[-sqrt(-x**2 - 2*x - 6), sqrt(-x**2 - 2*x - 6), -sqrt(-x**2 - 2*x - 5), sqrt(-x**2 - 2*x - 5), -sqrt(-x**2 - 2*x - 4), sqrt(-x**2 - 2*x - 4), -sqrt(-x**2 - 2*x - 3), sqrt(-x**2 - 2*x - 3), -sqrt(-x**2 - 2*x - 2), sqrt(-x**2 - 2*x - 2), -I*(x + 1), I*(x + 1), -sqrt(-x*(x + 2)), sqrt(-x*(x + 2)), -sqrt(-x**2 - 2*x + 1), sqrt(-x**2 - 2*x + 1), -sqrt(-x**2 - 2*x + 2), sqrt(-x**2 - 2*x + 2), -sqrt(-(x - 1)*(x + 3)), sqrt(-(x - 1)*(x + 3)), -sqrt(-x**2 - 2*x + 4), sqrt(-x**2 - 2*x + 4)]
cartesian line: -sqrt(-x**2 - 2*x - 6) for x over (-10.0, 10.0) red
cartesian line: sqrt(-x**2 - 2*x - 6) for x over (-10.0, 10.0) green
cartesian line: -sqrt(-x**2 - 2*x - 5) for x over (-10.0, 10.0) blue
cartesian line: sqrt(-x**2 - 2*x - 5) for x over (-10.0, 10.0) brown
cartesian line: -sqrt(-x**2 - 2*x - 4) for x over (-10.0, 10.0) orange
cartesian line: sqrt(-x**2 - 2*x - 4) for x over (-10.0, 10.0) purple
cartesian line: -sqrt(-x**2 - 2*x - 3) for x over (-10.0, 10.0) pink
cartesian line: sqrt(-x**2 - 2*x - 3) for x over (-10.0, 10.0) gray
cartesian line: -sqrt(-x**2 - 2*x - 2) for x over (-10.0, 10.0) skyblue
cartesian line: sqrt(-x**2 - 2*x - 2) for x over (-10.0, 10.0) yellow
cartesian line: -I*(x + 1) for x over (-10.0, 10.0) red
cartesian line: I*(x + 1) for x over (-10.0, 10.0) green
cartesian line: -sqrt(-x*(x + 2)) for x over (-10.0, 10.0) blue
cartesian line: sqrt(-x*(x + 2)) for x over (-10.0, 10.0) brown
cartesian line: -sqrt(-x**2 - 2*x + 1) for x over (-10.0, 10.0) orange
cartesian line: sqrt(-x**2 - 2*x + 1) for x over (-10.0, 10.0) purple
cartesian line: -sqrt(-x**2 - 2*x + 2) for x over (-10.0, 10.0) pink
cartesian line: sqrt(-x**2 - 2*x + 2) for x over (-10.0, 10.0) gray
cartesian line: -sqrt(-(x - 1)*(x + 3)) for x over (-10.0, 10.0) skyblue
cartesian line: sqrt(-(x - 1)*(x + 3)) for x over (-10.0, 10.0) yellow
%