2019年2月25日月曜日

数学 - Python - 解析学 - 積分 - 積分の応用 - 回転体の体積(楕円、図形をx軸の周りに回転してできる立体の体積)

1. $\begin{array}{}y=0\\ {a}^{2}{x}^{2}={a}^{2}{b}^{2}\\ {x}^{2}={b}^{2}\\ {y}^{2}=\frac{{a}^{2}{b}^{2}-{a}^{2}{x}^{2}}{{b}^{2}}\\ =\frac{{a}^{2}}{{b}^{2}}\left({b}^{2}-{x}^{2}\right)\end{array}$

求める回転体の体積.

$\begin{array}{}\underset{-b}{\overset{b}{\int }}\pi {y}^{2}\mathrm{dx}\\ =\frac{2\pi {a}^{2}}{{b}^{2}}\underset{0}{\overset{b}{\int }}\left({b}^{2}-{x}^{2}\right)\mathrm{dx}\\ =\frac{2\pi {a}^{2}}{{b}^{2}}{\left[{b}^{2}x-\frac{1}{3}{x}^{3}\right]}_{0}^{b}\\ =\frac{2\pi {a}^{2}}{{b}^{2}}\left({b}^{3}-\frac{1}{3}{b}^{3}\right)\\ =\frac{4\pi {a}^{2}b}{3}\end{array}$

コード

Python 3

#!/usr/bin/env python3
from sympy import pprint, symbols, Integral, pi, plot, sqrt, solve, Rational

x = symbols('x')
a = 2
b = 3
f = sqrt(Rational(a ** 2, b ** 2) * (b ** 2 - x ** 2))
x1, x2 = -b, b

I = Integral(pi * f ** 2, (x, x1, x2))

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

g = -f
x0 = -5
x3 = 5
p = plot((f, (x, x0, x1)),
(f, (x, x1, x2)),
(f, (x, x2, x3)),
(g, (x, x0, x1)),
(g, (x, x1, x2)),
(g, (x, x2, x3)),
legend=True, show=False)
colors = ['red', 'green', 'blue', 'brown', 'orange', 'purple']
for s, color in zip(p, colors):
s.line_color = color

p.show()
p.save('sample8.png')


C:\Users\...> py -3 sample8.py
3
⌠
⎮      ⎛   2    ⎞
⎮  4⋅π⋅⎝- x  + 9⎠
⎮  ────────────── dx
⎮        9
⌡
-3

16⋅π

C:\Users\...>