## 2019年2月16日土曜日

### 数学 - Python - 解析学 - 積分 - 積分の応用 - 面積(直線、累乗(平方)、交点、直交座標)

1. 2つの曲線の交点を求める。

$\begin{array}{}{x}^{2}-\left(x+1\right)=0\\ {x}^{2}-x-1=0\\ x=\frac{1±\sqrt{1+4}}{2}\\ =\frac{1±\sqrt{5}}{2}\end{array}$

不定積分。

$\begin{array}{}\int \left(\left(x+1\right)-{x}^{2}\right)\mathrm{dx}\\ =-\frac{1}{3}{x}^{3}+\frac{1}{2}{x}^{2}+x\end{array}$

よって求める2曲線の2つの交点の間の面積は、

$\begin{array}{}\left(-\frac{1}{3}{\left(\frac{1+\sqrt{5}}{2}\right)}^{3}+\frac{1}{2}{\left(\frac{1+\sqrt{5}}{2}\right)}^{2}+\frac{1+\sqrt{5}}{2}\right)\\ -\left(-\frac{1}{3}{\left(\frac{1-\sqrt{5}}{2}\right)}^{3}+\frac{1}{2}{\left(\frac{1-\sqrt{5}}{2}\right)}^{2}+\frac{1-\sqrt{5}}{2}\right)\\ =-\frac{1}{3}\left({\left(\frac{1+\sqrt{5}}{2}\right)}^{3}-{\left(\frac{1-\sqrt{5}}{2}\right)}^{3}\right)+\frac{1}{2}\left({\left(\frac{1+\sqrt{5}}{2}\right)}^{2}-{\left(\frac{1-\sqrt{5}}{2}\right)}^{2}\right)+\sqrt{5}\\ =-\frac{1}{3}·\frac{1}{8}\left(\left(1+\sqrt{5}\right)-\left(1-\sqrt{5}\right)\right)\left({\left(1+\sqrt{5}\right)}^{2}+\left(1+\sqrt{5}\right)\left(1-\sqrt{5}\right)+{\left(1-\sqrt{5}\right)}^{2}\right)\\ +\frac{1}{2}·\frac{1}{4}\left(\left(1+\sqrt{5}\right)-\left(1-\sqrt{5}\right)\right)\left(\left(1+\sqrt{5}\right)+\left(1-\sqrt{5}\right)\right)\\ +\sqrt{5}\\ =-\frac{1}{3}·\frac{1}{8}·2\sqrt{5}\left(1+2\sqrt{5}+5+1-5+1-2\sqrt{5}+5\right)\\ +\frac{1}{2}\frac{1}{4}·2\sqrt{5}·2\\ +\sqrt{5}\\ =-\frac{1}{3}·\frac{1}{4}·\sqrt{5}·8+\frac{\sqrt{5}}{2}+\sqrt{5}\\ =-\frac{2\sqrt{5}}{3}+\frac{\sqrt{5}}{2}+\sqrt{5}\\ =\frac{\left(-4+3+6\right)\sqrt{5}}{6}\\ =\frac{5\sqrt{5}}{6}\end{array}$

コード

Python 3

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

x = symbols('x')
f = x + 1
g = x ** 2
xs = solve(f - g)
pprint(xs)
x2, x1 = xs
I = Integral(f - g, (x, x1, x2))

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

a, b, c, d = x1 - 1, x1, x2, x2 + 1
p = plot((f, (x, a, b)),
(f, (x, b, c)),
(f, (x, c, d)),
(g, (x, a, b)),
(g, (x, b, c)),
(g, (x, c, d)),
legend=True,
show=False)

colors = ['red', 'green', 'blue', 'brown', 'orange', 'pink']

for i, s in enumerate(p):
s.line_color = colors[i]
p.save('sample15.png')


C:\Users\...> py -3 sample15.py
⎡1   √5    √5   1⎤
⎢─ + ──, - ── + ─⎥
⎣2   2     2    2⎦
1   √5
─ + ──
2   2
⌠
⎮     ⎛   2        ⎞
⎮     ⎝- x  + x + 1⎠ dx
⌡
√5   1
- ── + ─
2    2

5⋅√5
────
6

C:\Users\...>