## 2020年3月10日火曜日

### 数学 - Python - 解析学 - 多変数の関数 - ベクトルの微分 - 曲線の長さ - 対数関数、置換積分法

1. $\begin{array}{l}X\text{'}\left(t\right)=\left(1,\frac{1}{t}\right)\\ \int \sqrt{1+\frac{1}{{t}^{2}}}\mathrm{dt}\\ =\int \sqrt{\frac{1+{t}^{2}}{{t}^{2}}}\mathrm{dt}\\ =\int \frac{\sqrt{1+{t}^{2}}}{t}\mathrm{dt}\\ {u}^{2}=1+{t}^{2}\\ 2u·\frac{du}{\mathrm{dt}}=2t\\ \mathrm{dt}=\frac{u}{t}du\\ \int \frac{u}{t}·\frac{u}{t}du\\ =\int \frac{{u}^{2}}{{u}^{2}-1}du\\ =\int \frac{{u}^{2}-1+1}{{u}^{2}-1}du\\ =\int \left(1+\frac{1}{{u}^{2}-1}\right)du\\ =\int du+\int \frac{1}{\left(u+1\right)\left(u-1\right)}du\\ =u+\frac{1}{2}\int \left(\frac{1}{u-1}-\frac{1}{u+1}\right)du\\ =u+\frac{1}{2}\left(\mathrm{log}\left(u-1\right)-\mathrm{log}\left(u+1\right)\right)\\ =u+\frac{1}{2}\mathrm{log}\frac{u-1}{u+1}\end{array}$

よって、

$\begin{array}{l}{\int }_{1}^{2}\sqrt{1+\frac{1}{{t}^{2}}}\mathrm{dt}\\ ={\left[u+\frac{1}{2}\mathrm{log}\frac{u-1}{u+1}\right]}_{\sqrt{2}}^{\sqrt{5}}\\ =\sqrt{5}-\sqrt{2}+\frac{1}{2}\mathrm{log}\frac{\sqrt{5}-1}{\sqrt{5}+1}·\frac{\sqrt{2}+1}{\sqrt{2}-1}\end{array}$

2. $\begin{array}{l}{\int }_{3}^{5}\sqrt{1+\frac{1}{{t}^{2}}}\mathrm{dt}\\ ={\left[u+\frac{1}{2}\mathrm{log}\frac{u-1}{u+1}\right]}_{\sqrt{10}}^{\sqrt{26}}\\ =\sqrt{26}-\sqrt{10}+\frac{1}{2}\mathrm{log}\frac{\sqrt{26}-1}{\sqrt{26}+1}·\frac{\sqrt{10}+1}{\sqrt{10}-1}\end{array}$

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import symbols, Integral, Derivative, log, sqrt
from sympy.plotting import plot_parametric

print('5.')

t, u = symbols('t, u', real=True)
x = t
x1 = Derivative(x, t, 1).doit()
y = log(t)
y1 = Derivative(y, t, 1).doit()
f = u + log((u - 1) / (u + 1)) / 2

class MyTestCase(TestCase):
def test_a(self):
self.assertEqual(
float(Integral(sqrt(x1 ** 2 + y1 ** 2), (t, 1, 2)).doit()),
float(f.subs({u: sqrt(5)}) - f.subs({u: sqrt(2)})))

def test_b(self):
self.assertEqual(
float(Integral(sqrt(x1 ** 2 + y1 ** 2), (t, 3, 5)).doit()),
float(f.subs({u: sqrt(26)}) - f.subs({u: sqrt(10)})))

colors = ['red', 'green', 'blue', 'brown', 'orange',
'purple', 'pink', 'gray', 'skyblue', 'yellow']

p = plot_parametric(*[(x, y, (t, t1, t2))
for t1, t2 in [(0.1, 1), (1, 2), (2, 3), (3, 5), (5, 10)]],
legend=False,
show=False)

for o, color in zip(p, colors):
o.line_color = color
p.show()
p.save('sample5.png')

if __name__ == "__main__":
main()


% ./sample5.py -v
5.
test_a (__main__.MyTestCase) ... ok
test_b (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 2 tests in 4.456s

OK
%