多変数の関数 グラフと等位線 だ円、直線、2次方程式の解
続 解析入門 (原書第2版) (S.ラング(著)、松坂 和夫(翻訳)、片山 孝次(翻訳)、岩波書店)の第3章(多変数の関数)、1(グラフと等位線)の練習問題9、10、11.の解答を求めてみる。
9
のとき、
のときはだ円
10
直線。
11
のとき、
または
のとき、
よって等位線は直線で、
コード
#!/usr/bin/env python3
from sympy import plot, solve, Rational
from sympy.plotting import plot3d
from sympy.abc import x, y
print('9, 10, 11.')
fs = [
x ** 2 / 4 + y ** 2 / 16,
2 * x - 3 * y,
x * y / (x ** 2 + y ** 2),
]
css = [
range(-2, 3),
range(-5, 5),
[-Rational(1, 2), -Rational(1, 3), Rational(1, 3), Rational(1, 2)]
]
colors = ['red', 'green', 'blue', 'brown', 'orange',
'purple', 'pink', 'gray', 'skyblue', 'yellow']
for i, (f, cs) in enumerate(zip(fs, css), 9):
print(f'{i}.')
p = plot3d(f, show=False)
p.save(f'sample{i}_1.png')
ys = []
for c in cs:
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()
入出力結果
% ./sample9.py
9, 10, 11.
9.
cartesian line: -2*sqrt(-x**2 - 8) for x over (-10.0, 10.0) red
cartesian line: 2*sqrt(-x**2 - 8) for x over (-10.0, 10.0) green
cartesian line: -2*sqrt(-x**2 - 4) for x over (-10.0, 10.0) blue
cartesian line: 2*sqrt(-x**2 - 4) for x over (-10.0, 10.0) brown
cartesian line: -2*I*x for x over (-10.0, 10.0) orange
cartesian line: 2*I*x for x over (-10.0, 10.0) purple
cartesian line: -2*sqrt(4 - x**2) for x over (-10.0, 10.0) pink
cartesian line: 2*sqrt(4 - x**2) for x over (-10.0, 10.0) gray
cartesian line: -2*sqrt(8 - x**2) for x over (-10.0, 10.0) skyblue
cartesian line: 2*sqrt(8 - x**2) for x over (-10.0, 10.0) yellow
10.
cartesian line: 2*x/3 + 5/3 for x over (-10.0, 10.0) red
cartesian line: 2*x/3 + 4/3 for x over (-10.0, 10.0) green
cartesian line: 2*x/3 + 1 for x over (-10.0, 10.0) blue
cartesian line: 2*x/3 + 2/3 for x over (-10.0, 10.0) brown
cartesian line: 2*x/3 + 1/3 for x over (-10.0, 10.0) orange
cartesian line: 2*x/3 for x over (-10.0, 10.0) purple
cartesian line: 2*x/3 - 1/3 for x over (-10.0, 10.0) pink
cartesian line: 2*x/3 - 2/3 for x over (-10.0, 10.0) gray
cartesian line: 2*x/3 - 1 for x over (-10.0, 10.0) skyblue
cartesian line: 2*x/3 - 4/3 for x over (-10.0, 10.0) yellow
11.
cartesian line: -x for x over (-10.0, 10.0) red
cartesian line: x*(-3 + sqrt(5))/2 for x over (-10.0, 10.0) green
cartesian line: -x*(sqrt(5) + 3)/2 for x over (-10.0, 10.0) blue
cartesian line: x*(3 - sqrt(5))/2 for x over (-10.0, 10.0) brown
cartesian line: x*(sqrt(5) + 3)/2 for x over (-10.0, 10.0) orange
cartesian line: x for x over (-10.0, 10.0) purple
%