## 2020年3月26日木曜日

### 数学 - Python - 解析学 - 多変数の関数 - 多変数の関数 - グラフと等位線 - 極座標に変換、三角関数(正弦と余弦)、加法定理、倍角

1. $\begin{array}{l}\frac{4xy\left({x}^{2}-{y}^{2}\right)}{{x}^{2}+{y}^{2}}=c\\ 4xy\left({x}^{2}-{y}^{2}\right)=c\left({x}^{2}+{y}^{2}\right)\end{array}$

極座標に変換して考える。

$\begin{array}{l}x=r\mathrm{cos}\theta \\ y=r\mathrm{sin}\theta \end{array}$

とおくと、

$\begin{array}{l}4{r}^{2}\mathrm{cos}\theta \mathrm{sin}\theta \left({r}^{2}{\mathrm{cos}}^{2}\theta -{r}^{2}{\mathrm{sin}}^{2}\theta \right)=c\left({r}^{2}{\mathrm{cos}}^{2}\theta +{r}^{2}{\mathrm{sin}}^{2}\theta \right)\\ 4{r}^{2}\mathrm{cos}\theta \mathrm{sin}\theta \left({\mathrm{cos}}^{2}\theta -{\mathrm{sin}}^{2}\theta \right)=c\\ 4{r}^{2}\frac{\mathrm{sin}2\theta }{2}{\mathrm{cos}}^{2}\theta =c\\ 2{r}^{2}\mathrm{sin}2\theta \mathrm{cos}2\theta =c\\ {r}^{2}\mathrm{sin}4\theta =c\end{array}$

コード

#!/usr/bin/env python3
from sympy import symbols, plot, solve, Rational
from sympy.plotting import plot3d

print('13.')

x, y, c = symbols('x, y, c', real=True)
eq = 4 * x * y * (x ** 2 - y ** 2) / (x ** 2 + y ** 2)
p = plot3d(eq, show=False)

p.xlabel = x
p.ylabel = y
p.save('sample13.png')

ys = solve(eq - c, y)

for i, c0 in enumerate([-10, -2, -1, -Rational(1, 2), Rational(1, 2), 1, 2, 10]):
p = plot(*[f.subs({c: c0})
for f in ys],
(x, -10, 10),
ylim=(-10, 10),
legend=True,
show=False)
colors = ['red', 'green', 'blue', 'brown', 'orange',
'purple', 'pink', 'gray', 'skyblue', 'yellow']

for o, color in zip(p, colors):
o.line_color = color
p.save(f'sample13_{i}.png')
p.show()


% ./sample13.py
13.
%