## 2019年1月31日木曜日

### 数学 - Python - 解析学 - 積分 - 積分の応用 - 曲線の長さ(三角関数(正弦)、半角、累乗(べき乗、平方)、極座標表示)

1. $\begin{array}{}\underset{0}{\overset{\pi }{\int }}\sqrt{{\left({\mathrm{sin}}^{2}\left(\frac{\theta }{2}\right)\right)}^{2}+{\left(\frac{d}{d\theta }{\mathrm{sin}}^{2}\left(\frac{\theta }{2}\right)\right)}^{2}}d\theta \\ =\underset{0}{\overset{\pi }{\int }}\sqrt{{\mathrm{sin}}^{4}\left(\frac{\theta }{2}\right)+{\left(2\mathrm{sin}\left(\frac{\theta }{2}\right)\mathrm{cos}\left(\frac{\theta }{2}\right)·\frac{1}{2}\right)}^{2}}d\theta \\ =\underset{0}{\overset{\pi }{\int }}\sqrt{{\mathrm{sin}}^{4}\left(\frac{\theta }{2}\right)+{\mathrm{sin}}^{2}\left(\frac{\theta }{2}\right){\mathrm{cos}}^{2}\left(\frac{\theta }{2}\right)}d\theta \\ =\underset{0}{\overset{\pi }{\int }}\mathrm{sin}\left(\frac{\theta }{2}\right)\sqrt{{\mathrm{sin}}^{2}\left(\frac{\theta }{2}\right)+{\mathrm{cos}}^{2}\left(\frac{\theta }{2}\right)}d\theta \\ =\underset{0}{\overset{\pi }{\int }}\mathrm{sin}\left(\frac{\theta }{2}\right)d\theta \\ =2{\left[-\mathrm{cos}\left(\frac{\theta }{2}\right)\right]}_{0}^{\pi }\\ =2\end{array}$

コード

Python 3

#!/usr/bin/env python3
from sympy import pprint, symbols, Integral, Derivative, sqrt, cos, sin, pi
from sympy.plotting import plot_parametric

theta = symbols('θ')
r = sin(theta / 2) ** 2
x = r * cos(theta)
y = r * sin(theta)

I = Integral(sqrt(r ** 2 + Derivative(r, theta, 1) ** 2),
(theta, 0, pi))

# for o in [I, I.doit()]:
#     pprint(o.simplify())
#     print()

I = Integral(sin(theta / 2), (theta, 0, pi))
for o in [I, I.doit()]:
pprint(o.simplify())
print()

p = plot_parametric((x, y, (theta, 0, pi)),
(x, y, (theta, pi, 2 * pi)),
show=False)

colors = ['red', 'green']
for i, color in enumerate(colors):
p[i].line_color = color
p.save('sample20.png')


$python3 sample20.py π ⌠ ⎮ ⎛θ⎞ ⎮ sin⎜─⎟ dθ ⎮ ⎝2⎠ ⌡ 0 2$