## 2020年1月9日木曜日

### 数学 - Python - 解析学 - 積分の計算 - 定積分の計算 - 置換積分法、三角関数(正弦、余弦、正接)、平方、平方根、部分積分法、指数関数

1. $x=a\left(\mathrm{sin}t\right)$

とおくと、

$\begin{array}{l}\frac{\mathrm{dx}}{\mathrm{dt}}=a\left(\mathrm{cos}t\right)\\ {\int }_{0}^{a}\sqrt{{a}^{2}-{x}^{2}}\mathrm{dx}\\ =\underset{0}{\overset{\frac{\pi }{2}}{\int }}\sqrt{{a}^{2}-{a}^{2}{\mathrm{sin}}^{2}t}a\left(\mathrm{cos}t\right)\mathrm{dt}\\ ={a}^{2}\underset{0}{\overset{\frac{\pi }{2}}{\int }}\sqrt{1-{\mathrm{sin}}^{2}t}\mathrm{cos}t\mathrm{dt}\\ ={a}^{2}\underset{0}{\overset{\frac{\pi }{2}}{\int }}{\mathrm{cos}}^{2}t\mathrm{dt}\\ ={a}^{2}\underset{0}{\overset{\frac{\pi }{2}}{\int }}\frac{\mathrm{cos}2t+1}{2}\mathrm{dt}\\ =\frac{{a}^{2}}{2}{\left[\frac{1}{2}\mathrm{sin}2t+t\right]}_{0}^{\frac{\pi }{2}}\\ =\frac{{a}^{2}}{2}·\frac{\pi }{2}\\ =\frac{\pi {a}^{2}}{4}\end{array}$

2. $\begin{array}{l}{\int }_{0}^{a}\frac{\mathrm{dx}}{\sqrt{{a}^{2}-{x}^{2}}}\\ =\underset{0}{\overset{\frac{\pi }{2}}{\int }}\frac{a\left(\mathrm{cos}t\right)}{a\left(\mathrm{cos}t\right)}\mathrm{dt}\\ =\frac{\pi }{2}\end{array}$

3. $\begin{array}{l}{\int }_{0}^{1}\frac{\mathrm{dx}}{1+x+{x}^{2}}\\ ={\int }_{0}^{1}\frac{\mathrm{dx}}{{\left(x+\frac{1}{2}\right)}^{2}+\frac{3}{4}}\\ x+\frac{1}{2}=\frac{\sqrt{3}}{2}t\\ \frac{\mathrm{dx}}{\mathrm{dt}}=\frac{\sqrt{3}}{2}\\ {\int }_{0}^{1}\frac{\mathrm{dy}}{1+x+{x}^{2}}\\ =\frac{\sqrt{3}}{2}\underset{\frac{1}{\sqrt{3}}}{\overset{\sqrt{3}}{\int }}\frac{\mathrm{dt}}{\frac{3}{4}{t}^{2}+\frac{3}{4}}\\ =\frac{2\sqrt{3}}{3}\left(\mathrm{arctan}\sqrt{3}-\mathrm{arctan}\frac{1}{\sqrt{3}}\right)\\ =\frac{2\sqrt{3}}{3}\left(\frac{\pi }{3}-\frac{\pi }{6}\right)\\ =\frac{2\sqrt{3}}{3}·\frac{\pi }{6}\\ =\frac{\sqrt{3}}{9}\pi \\ =\frac{\pi }{3\sqrt{3}}\end{array}$

4. $\begin{array}{l}{\int }_{-1}^{1}\frac{\mathrm{dy}}{{\left(1+{x}^{2}\right)}^{2}}\\ =2{\int }_{0}^{1}\frac{\mathrm{dx}}{{\left(1+{x}^{2}\right)}^{2}}\\ \int \frac{\mathrm{dx}}{{\left(1+{x}^{2}\right)}^{2}}\\ =\frac{1}{2\left(2-1\right)}\left(\frac{x}{{x}^{2}+1}+\left(2·2-3\right)\int \frac{\mathrm{dx}}{1+{x}^{2}}\right)\\ =\frac{1}{2}\left(\frac{x}{{x}^{2}+1}+\mathrm{arctan}x\right)\\ {\int }_{-1}^{1}\frac{\mathrm{dx}}{{\left(1+{x}^{2}\right)}^{2}}\\ ={\left[\frac{x}{{x}^{2}+1}+\mathrm{arctan}x\right]}_{0}^{1}\\ =\frac{1}{2}+\mathrm{arctan}1-\mathrm{arctan}0\\ =\frac{1}{2}+\frac{\pi }{4}\end{array}$

5. $\begin{array}{l}\mathrm{tan}\frac{\theta }{2}=t\\ \frac{1}{2{\mathrm{cos}}^{2}\frac{\theta }{2}}=\frac{\mathrm{dt}}{d\theta }\\ {\int }_{0}^{\pi }\frac{d\theta }{1+a\left(\mathrm{cos}\theta \right)}\\ ={\int }_{0}^{\infty }\frac{1}{1+a\left(\mathrm{cos}\theta \right)}·2{\mathrm{cos}}^{2}\frac{\theta }{2}\mathrm{dt}\\ =\underset{b\to \infty }{\mathrm{lim}}{\int }_{0}^{b}\frac{2{\mathrm{cos}}^{2}\frac{\theta }{2}}{1+a\left({\mathrm{cos}}^{2}\frac{\theta }{2}-{\mathrm{sin}}^{2}\frac{\theta }{2}\right)}\mathrm{dt}\\ =\underset{b\to \infty }{\mathrm{lim}}{\int }_{0}^{b}\frac{2{\mathrm{cos}}^{2}\frac{\theta }{2}}{{\mathrm{sin}}^{2}\frac{\theta }{2}+{\mathrm{cos}}^{2}\frac{\theta }{2}+a\left({\mathrm{cos}}^{2}\frac{\theta }{2}-{\mathrm{sin}}^{2}\frac{\theta }{2}\right)}\mathrm{dt}\\ =\underset{b\to \infty }{\mathrm{lim}}{\int }_{0}^{b}\frac{2}{{t}^{2}+1+a\left(1-{t}^{2}\right)}\mathrm{dt}\\ =2\underset{b\to \infty }{\mathrm{lim}}{\int }_{0}^{b}\frac{1}{\left(1-a\right){t}^{2}+1+a}\mathrm{dt}\\ =\frac{2}{1-a}\underset{b\to \infty }{\mathrm{lim}}{\int }_{0}^{b}\frac{1}{{t}^{2}+\frac{1+a}{1-a}}\mathrm{dt}\\ =\frac{2}{1-a}·\sqrt{\frac{1-a}{1+a}}\underset{b\to \infty }{\mathrm{lim}}{\left[\mathrm{arctan}\sqrt{\frac{1-a}{1+a}}t\right]}_{0}^{b}\\ =\frac{2}{\sqrt{1-{a}^{2}}}\underset{b\to \infty }{\mathrm{lim}}\mathrm{arctan}\sqrt{\frac{1-a}{1+a}}b\\ =\frac{2}{\sqrt{1-{a}^{2}}}·\frac{\pi }{2}\\ =\frac{\pi }{\sqrt{1-{a}^{2}}}\end{array}$

6. $\begin{array}{l}\int \frac{x\mathrm{arcsin}x}{\sqrt{1-{x}^{2}}}\mathrm{dx}\\ =x{\mathrm{arcsin}}^{2}x-\int \left(\mathrm{arcsin}x+\frac{x}{\sqrt{1-{x}^{2}}}\right)\mathrm{arcsin}x\mathrm{dx}\\ =x{\mathrm{arcsin}}^{2}x-\int {\mathrm{arcsin}}^{2}x\mathrm{dx}-\int \frac{x\mathrm{arcsin}x}{\sqrt{1-{x}^{2}}}\mathrm{dx}\\ \int \frac{x\mathrm{arcsin}x}{\sqrt{1-{x}^{2}}}\\ =\frac{1}{2}\left(x{\mathrm{arcsin}}^{2}x-\int {\mathrm{arcsin}}^{2}x\mathrm{dx}\right)\\ t=\mathrm{arcsin}x\\ \frac{\mathrm{dt}}{\mathrm{dx}}=\frac{1}{\sqrt{1-{x}^{2}}}\\ \mathrm{sin}t=x\\ \int {\mathrm{arcsin}}^{2}x\mathrm{dx}\\ =\int t\sqrt[2]{1-{x}^{2}}\mathrm{dt}\\ =\int t\sqrt[2]{1-{\mathrm{sin}}^{2}t}\mathrm{dt}\\ =\int {t}^{2}\mathrm{cos}t\mathrm{dt}\\ ={t}^{2}\mathrm{sin}t-2\int t\mathrm{sin}t\mathrm{dt}\\ ={t}^{2}\mathrm{sin}t-2\left(-t\mathrm{cos}t+\int \mathrm{cos}t\mathrm{dt}\right)\\ {\int }_{-1}^{1}\frac{x\mathrm{arcsin}x}{\sqrt{1-{x}^{2}}}\mathrm{dx}\\ =\frac{1}{2}{\left[x{\mathrm{arcsin}}^{2}x\right]}_{-1}^{1}-\frac{1}{2}{\left[{t}^{2}\mathrm{sin}t\right]}_{-\frac{\pi }{2}}^{\frac{\pi }{2}}-{\left[t\mathrm{cos}t\right]}_{-\frac{\pi }{2}}^{\frac{\pi }{2}}+{\left[\mathrm{sin}t\right]}_{-\frac{\pi }{2}}^{\frac{\pi }{2}}\\ =\frac{1}{2}\left({\mathrm{arcsin}}^{2}1+{\mathrm{arcsin}}^{2}\left(-1\right)\right)-\frac{1}{2}·\frac{{\pi }^{2}}{4}·2+2\\ =\frac{1}{2}\left(\frac{{\pi }^{2}}{4}+\frac{{\pi }^{2}}{4}\right)-\frac{{\pi }^{2}}{4}+2\\ =2\end{array}$

7. $\begin{array}{l}\int {e}^{-ax}\mathrm{sin}bx\mathrm{dx}\\ =-\frac{1}{a}{e}^{-ax}\mathrm{sin}bx+\frac{b}{a}\int {e}^{-ax}\mathrm{cos}bx\mathrm{dx}\\ =-\frac{1}{a}{e}^{-ax}\mathrm{sin}bx+\frac{b}{a}\left(-\frac{1}{a}{e}^{-ax}\mathrm{cos}bx-\frac{b}{a}\int {e}^{-ax}\mathrm{sin}bx\mathrm{dx}\right)\\ =-\frac{1}{a}{e}^{-ax}\mathrm{sin}bx-\frac{b}{{a}^{2}}{e}^{-ax}\mathrm{cos}bx-\frac{{b}^{2}}{{a}^{2}}\int {e}^{-ax}\mathrm{sin}bx\mathrm{dx}\\ \left(1+\frac{{b}^{2}}{{a}^{2}}\right)\int {e}^{-ax}\mathrm{sin}bx\mathrm{dx}=-\frac{1}{a}{e}^{-ax}\mathrm{sin}bx-\frac{b}{{a}^{2}}{e}^{-ax}\mathrm{cos}bx\\ \int {e}^{-ax}\mathrm{sin}bx\mathrm{dx}=-\frac{{a}^{2}}{{a}^{2}+{b}^{2}}·\frac{1}{a}\left({e}^{-ax}\mathrm{sin}bx+\frac{b}{a}{e}^{-ax}\mathrm{cos}bx\right)\\ {\int }_{0}^{+\infty }{e}^{-ax}\mathrm{sin}bxdx\\ =\underset{A\to \infty }{\mathrm{lim}}{\int }_{0}^{A}{e}^{-ax}\mathrm{sin}bx\mathrm{dx}\\ =-\frac{a}{{a}^{2}+{b}^{2}}\underset{A\to \infty }{\mathrm{lim}}{\left[{e}^{-ax}\left(\mathrm{sin}bx+\frac{b}{a}\mathrm{cos}bx\right)\right]}_{0}^{A}\\ =-\frac{a}{{a}^{2}+{b}^{2}}\underset{A\to \infty }{\mathrm{lim}}\left({e}^{-aA}\left(\mathrm{sin}bA+\frac{b}{a}\mathrm{cos}bA\right)-\left(\mathrm{sin}0+\frac{b}{a}\mathrm{cos}0\right)\right)\\ =-\frac{a}{{a}^{2}+{b}^{2}}·\left(-\frac{b}{a}\right)\\ =\frac{b}{{a}^{2}+{b}^{2}}\end{array}$

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import pprint, symbols, sqrt, sin, cos, asin, exp, Integral, pi, Rational, oo, plot

print('1.')

x = symbols('x')
a = symbols('a', positive=True)
b = symbols('b', nonzero=True)
fs = [sqrt(a ** 2 - x ** 2),
1 / sqrt(a ** 2 - x ** 2),
1 / (1 + x + x ** 2),
1 / (1 + x ** 2) ** 2,
1 / (1 + Rational(1, 2) * cos(x)),
x * asin(x) / sqrt(1 - x ** 2),
exp(-1 * 1 * x) * sin(2 * x)]

class MyTestCase(TestCase):
def test1(self):
self.assertEqual(Integral(fs[0], (x, 0, a)).doit(), pi * a ** 2 / 4)

def test2(self):
a = symbols('a', positive=True)
self.assertEqual(Integral(fs[1], (x, 0, a)).doit(), pi / 2)

def test3(self):
self.assertEqual(Integral(fs[2], (x, 0, 1)).doit(), pi / (3 * sqrt(3)))

def test4(self):
self.assertEqual(
Integral(fs[3], (x, -1, 1)).doit(), Rational(1, 2) + pi / 4)

def test5(self):
d = {a: Rational(1, 2)}
self.assertEqual(
Integral(fs[4].subs(d), (x, 0, pi)).doit(), (pi / sqrt(1 - a ** 2)).subs(d))

def test6(self):
self.assertEqual(Integral(fs[5], (x, -1, 1)).doit(), 2)

def test7(self):
d = {a: 1, b: 2}
self.assertEqual(
Integral(fs[6].subs(d), (x, 0, oo)).doit(
), (b / (a ** 2 + b ** 2)).subs(d))

p = plot(*[f.subs({a: 1, b: 2}) for f in fs],
(x, -5, 5),
ylim=(-5, 5),
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.show()
p.save('sample1.png')

if __name__ == '__main__':
main()


% ./sample1.py -v
1.
test1 (__main__.MyTestCase) ... ok
test2 (__main__.MyTestCase) ... ok
test3 (__main__.MyTestCase) ... ok
test4 (__main__.MyTestCase) ... ok
test5 (__main__.MyTestCase) ... ok
test6 (__main__.MyTestCase) ... ok
test7 (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 7 tests in 2.425s

OK
%