## 2020年3月8日日曜日

### 数学 - Python - 解析学 - 多変数の関数 - ベクトルの微分 - 曲線の長さ - スパイラル(正弦と余弦、4倍角)、積分

1. $\begin{array}{l}X\text{'}\left(t\right)=\left(-4\mathrm{sin}4t,4\mathrm{cos}4t,1\right)\\ \underset{0}{\overset{\frac{\pi }{8}}{\int }}\sqrt{{4}^{2}{\mathrm{sin}}^{2}4t+{4}^{2}{\mathrm{cos}}^{2}4t+1}\mathrm{dt}\\ =\underset{0}{\overset{\frac{\pi }{8}}{\int }}\sqrt{17}\mathrm{dt}\\ =\frac{\sqrt{17}}{8}\pi \end{array}$

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import symbols, Matrix, Derivative, sin, cos, sqrt, Integral, pi
from sympy.plotting import plot3d_parametric_line

print('3.')

t = symbols('t')
x = Matrix([cos(4 * t), sin(4 * t), t])
x1 = Matrix([Derivative(o, t, 1).doit() for o in x])

class MyTestCase(TestCase):
def test(self):
l = Integral(x1.norm(), (t, 0, pi / 8)).doit()
self.assertEqual(l, sqrt(17) * pi / 8)

colors = ['red', 'green', 'blue', 'brown', 'orange',
'purple', 'pink', 'gray', 'skyblue', 'yellow']
p = plot3d_parametric_line(*[(*x, (t, t1, t2))
for t1, t2 in [(-5, 0), (0, pi / 8), (pi / 8, 5)]],
legend=True,
show=False)
for o, color in zip(p, colors):
o.line_color = color
p.show()
p.save('sample3.png')

if __name__ == "__main__":
main()


% ./sample3.py -v
3.
test (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.533s

OK
%