多変数の関数 グラフと等位線 極座標、三角関数、正弦と余弦、長さと角
続 解析入門 (原書第2版) (S.ラング(著)、松坂 和夫(翻訳)、片山 孝次(翻訳)、岩波書店)の第3章(多変数の関数)、1(グラフと等位線)の練習問題13.の解答を求めてみる。
のとき、
または
のとき。
コード
#!/usr/bin/env python3
from sympy import plot, solve, Rational
from sympy.plotting import plot3d
from sympy.abc import x, y
print('13.')
f = 4 * x * y * (x ** 2 - y ** 2) / (x ** 2 + y ** 2)
colors = ['red', 'green', 'blue', 'brown', 'orange',
'purple', 'pink', 'gray', 'skyblue', 'yellow']
p = plot3d(f, show=False, xlabel=x, ylabel=y)
p.save(f'sample13_1.png')
ys = []
for c in [-2, -1, -Rational(1, 2), 0, Rational(1, 2), 1, 2]:
ys += solve(f - c, y)
p = plot(*ys,
(x, -2, 2),
ylim=(-2, 2),
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'sample13_2.png')
p.show()
入出力結果
% ./sample13.py
13.
cartesian line: -(3*x**2 + 1/(4*x**2))/(3*(-9*x + sqrt((-18*x - 1/(4*x**3))**2 - 4*(3*x**2 + 1/(4*x**2))**3)/2 - 1/(8*x**3))**(1/3)) - (-9*x + sqrt((-18*x - 1/(4*x**3))**2 - 4*(3*x**2 + 1/(4*x**2))**3)/2 - 1/(8*x**3))**(1/3)/3 + 1/(6*x) for x over (-2.0, 2.0) red
cartesian line: -(3*x**2 + 1/(4*x**2))/(3*(-1/2 - sqrt(3)*I/2)*(-9*x + sqrt((-18*x - 1/(4*x**3))**2 - 4*(3*x**2 + 1/(4*x**2))**3)/2 - 1/(8*x**3))**(1/3)) - (-1/2 - sqrt(3)*I/2)*(-9*x + sqrt((-18*x - 1/(4*x**3))**2 - 4*(3*x**2 + 1/(4*x**2))**3)/2 - 1/(8*x**3))**(1/3)/3 + 1/(6*x) for x over (-2.0, 2.0) green
cartesian line: -(3*x**2 + 1/(4*x**2))/(3*(-1/2 + sqrt(3)*I/2)*(-9*x + sqrt((-18*x - 1/(4*x**3))**2 - 4*(3*x**2 + 1/(4*x**2))**3)/2 - 1/(8*x**3))**(1/3)) - (-1/2 + sqrt(3)*I/2)*(-9*x + sqrt((-18*x - 1/(4*x**3))**2 - 4*(3*x**2 + 1/(4*x**2))**3)/2 - 1/(8*x**3))**(1/3)/3 + 1/(6*x) for x over (-2.0, 2.0) blue
cartesian line: -(3*x**2 + 1/(16*x**2))/(3*(-9*x/2 + sqrt((-9*x - 1/(32*x**3))**2 - 4*(3*x**2 + 1/(16*x**2))**3)/2 - 1/(64*x**3))**(1/3)) - (-9*x/2 + sqrt((-9*x - 1/(32*x**3))**2 - 4*(3*x**2 + 1/(16*x**2))**3)/2 - 1/(64*x**3))**(1/3)/3 + 1/(12*x) for x over (-2.0, 2.0) brown
cartesian line: -(3*x**2 + 1/(16*x**2))/(3*(-1/2 - sqrt(3)*I/2)*(-9*x/2 + sqrt((-9*x - 1/(32*x**3))**2 - 4*(3*x**2 + 1/(16*x**2))**3)/2 - 1/(64*x**3))**(1/3)) - (-1/2 - sqrt(3)*I/2)*(-9*x/2 + sqrt((-9*x - 1/(32*x**3))**2 - 4*(3*x**2 + 1/(16*x**2))**3)/2 - 1/(64*x**3))**(1/3)/3 + 1/(12*x) for x over (-2.0, 2.0) orange
cartesian line: -(3*x**2 + 1/(16*x**2))/(3*(-1/2 + sqrt(3)*I/2)*(-9*x/2 + sqrt((-9*x - 1/(32*x**3))**2 - 4*(3*x**2 + 1/(16*x**2))**3)/2 - 1/(64*x**3))**(1/3)) - (-1/2 + sqrt(3)*I/2)*(-9*x/2 + sqrt((-9*x - 1/(32*x**3))**2 - 4*(3*x**2 + 1/(16*x**2))**3)/2 - 1/(64*x**3))**(1/3)/3 + 1/(12*x) for x over (-2.0, 2.0) purple
cartesian line: -(3*x**2 + 1/(64*x**2))/(3*(-9*x/4 + sqrt((-9*x/2 - 1/(256*x**3))**2 - 4*(3*x**2 + 1/(64*x**2))**3)/2 - 1/(512*x**3))**(1/3)) - (-9*x/4 + sqrt((-9*x/2 - 1/(256*x**3))**2 - 4*(3*x**2 + 1/(64*x**2))**3)/2 - 1/(512*x**3))**(1/3)/3 + 1/(24*x) for x over (-2.0, 2.0) pink
cartesian line: -(3*x**2 + 1/(64*x**2))/(3*(-1/2 - sqrt(3)*I/2)*(-9*x/4 + sqrt((-9*x/2 - 1/(256*x**3))**2 - 4*(3*x**2 + 1/(64*x**2))**3)/2 - 1/(512*x**3))**(1/3)) - (-1/2 - sqrt(3)*I/2)*(-9*x/4 + sqrt((-9*x/2 - 1/(256*x**3))**2 - 4*(3*x**2 + 1/(64*x**2))**3)/2 - 1/(512*x**3))**(1/3)/3 + 1/(24*x) for x over (-2.0, 2.0) gray
cartesian line: -(3*x**2 + 1/(64*x**2))/(3*(-1/2 + sqrt(3)*I/2)*(-9*x/4 + sqrt((-9*x/2 - 1/(256*x**3))**2 - 4*(3*x**2 + 1/(64*x**2))**3)/2 - 1/(512*x**3))**(1/3)) - (-1/2 + sqrt(3)*I/2)*(-9*x/4 + sqrt((-9*x/2 - 1/(256*x**3))**2 - 4*(3*x**2 + 1/(64*x**2))**3)/2 - 1/(512*x**3))**(1/3)/3 + 1/(24*x) for x over (-2.0, 2.0) skyblue
cartesian line: 0 for x over (-2.0, 2.0) yellow
cartesian line: -x for x over (-2.0, 2.0) red
cartesian line: x for x over (-2.0, 2.0) green
cartesian line: -(3*x**2 + 1/(64*x**2))/(3*(9*x/4 + sqrt((9*x/2 + 1/(256*x**3))**2 - 4*(3*x**2 + 1/(64*x**2))**3)/2 + 1/(512*x**3))**(1/3)) - (9*x/4 + sqrt((9*x/2 + 1/(256*x**3))**2 - 4*(3*x**2 + 1/(64*x**2))**3)/2 + 1/(512*x**3))**(1/3)/3 - 1/(24*x) for x over (-2.0, 2.0) blue
cartesian line: -(3*x**2 + 1/(64*x**2))/(3*(-1/2 - sqrt(3)*I/2)*(9*x/4 + sqrt((9*x/2 + 1/(256*x**3))**2 - 4*(3*x**2 + 1/(64*x**2))**3)/2 + 1/(512*x**3))**(1/3)) - (-1/2 - sqrt(3)*I/2)*(9*x/4 + sqrt((9*x/2 + 1/(256*x**3))**2 - 4*(3*x**2 + 1/(64*x**2))**3)/2 + 1/(512*x**3))**(1/3)/3 - 1/(24*x) for x over (-2.0, 2.0) brown
cartesian line: -(3*x**2 + 1/(64*x**2))/(3*(-1/2 + sqrt(3)*I/2)*(9*x/4 + sqrt((9*x/2 + 1/(256*x**3))**2 - 4*(3*x**2 + 1/(64*x**2))**3)/2 + 1/(512*x**3))**(1/3)) - (-1/2 + sqrt(3)*I/2)*(9*x/4 + sqrt((9*x/2 + 1/(256*x**3))**2 - 4*(3*x**2 + 1/(64*x**2))**3)/2 + 1/(512*x**3))**(1/3)/3 - 1/(24*x) for x over (-2.0, 2.0) orange
cartesian line: -(3*x**2 + 1/(16*x**2))/(3*(9*x/2 + sqrt((9*x + 1/(32*x**3))**2 - 4*(3*x**2 + 1/(16*x**2))**3)/2 + 1/(64*x**3))**(1/3)) - (9*x/2 + sqrt((9*x + 1/(32*x**3))**2 - 4*(3*x**2 + 1/(16*x**2))**3)/2 + 1/(64*x**3))**(1/3)/3 - 1/(12*x) for x over (-2.0, 2.0) purple
cartesian line: -(3*x**2 + 1/(16*x**2))/(3*(-1/2 - sqrt(3)*I/2)*(9*x/2 + sqrt((9*x + 1/(32*x**3))**2 - 4*(3*x**2 + 1/(16*x**2))**3)/2 + 1/(64*x**3))**(1/3)) - (-1/2 - sqrt(3)*I/2)*(9*x/2 + sqrt((9*x + 1/(32*x**3))**2 - 4*(3*x**2 + 1/(16*x**2))**3)/2 + 1/(64*x**3))**(1/3)/3 - 1/(12*x) for x over (-2.0, 2.0) pink
cartesian line: -(3*x**2 + 1/(16*x**2))/(3*(-1/2 + sqrt(3)*I/2)*(9*x/2 + sqrt((9*x + 1/(32*x**3))**2 - 4*(3*x**2 + 1/(16*x**2))**3)/2 + 1/(64*x**3))**(1/3)) - (-1/2 + sqrt(3)*I/2)*(9*x/2 + sqrt((9*x + 1/(32*x**3))**2 - 4*(3*x**2 + 1/(16*x**2))**3)/2 + 1/(64*x**3))**(1/3)/3 - 1/(12*x) for x over (-2.0, 2.0) gray
cartesian line: -(3*x**2 + 1/(4*x**2))/(3*(9*x + sqrt((18*x + 1/(4*x**3))**2 - 4*(3*x**2 + 1/(4*x**2))**3)/2 + 1/(8*x**3))**(1/3)) - (9*x + sqrt((18*x + 1/(4*x**3))**2 - 4*(3*x**2 + 1/(4*x**2))**3)/2 + 1/(8*x**3))**(1/3)/3 - 1/(6*x) for x over (-2.0, 2.0) skyblue
cartesian line: -(3*x**2 + 1/(4*x**2))/(3*(-1/2 - sqrt(3)*I/2)*(9*x + sqrt((18*x + 1/(4*x**3))**2 - 4*(3*x**2 + 1/(4*x**2))**3)/2 + 1/(8*x**3))**(1/3)) - (-1/2 - sqrt(3)*I/2)*(9*x + sqrt((18*x + 1/(4*x**3))**2 - 4*(3*x**2 + 1/(4*x**2))**3)/2 + 1/(8*x**3))**(1/3)/3 - 1/(6*x) for x over (-2.0, 2.0) yellow
%