## 2020年7月18日土曜日

### 数学 - Python - 解析学 - ベクトルの微分 - 微分係数 - 速度ベクトル、指数関数、三角関数(正弦と余弦)、対数関数

1. $\frac{d}{\mathrm{dt}}\left({e}^{t},\mathrm{cos}t,\mathrm{sin}t\right)=\left({e}^{t},-\mathrm{sin}t,\mathrm{cos}t\right)$

2. $\frac{d}{\mathrm{dt}}\left(\mathrm{sin}\left(2t\right),\mathrm{log}\left(1+t\right),t\right)=\left(2\mathrm{cos}\left(2t\right),\frac{1}{1+t},1\right)$

3. $\frac{d}{\mathrm{dt}}\left(\mathrm{cos}t,\mathrm{sin}t\right)=\left(-\mathrm{sin}t,\mathrm{cos}t\right)$

4. $\frac{d}{\mathrm{dt}}\left(\mathrm{cos}3t,\mathrm{sin}3t\right)=\left(-3\mathrm{sin}3t,3\mathrm{cos}3t\right)$

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import Matrix, sin, cos, exp, log, Derivative
from sympy.abc import t
from sympy.plotting import plot3d_parametric_line

print('1, 2, 3, 4.')

class Test(TestCase):
def test1(self):
self.assertEqual(
Derivative(Matrix([exp(t), cos(t), sin(t)]), t, 1).doit(),
Matrix([exp(t), -sin(t), cos(t)])
)

def test2(self):
self.assertEqual(
Derivative(Matrix([sin(2 * t), log(1 + t), t]), t, 1).doit(),
Matrix([2 * cos(2 * t), 1 / (1 + t), 1])
)

def test3(self):
self.assertEqual(
Derivative(Matrix([cos(t), sin(t)]), t, 1).doit(),
Matrix([-sin(t), cos(t)])
)

def test4(self):
self.assertEqual(
Derivative(Matrix([cos(3 * t), sin(3 * t)]), t, 1).doit(),
Matrix([-3 * sin(3 * t), 3 * cos(3 * t)])
)

p = plot3d_parametric_line(
(exp(t), cos(t), sin(t), (t, -5, 5)),
*[(exp(t0) + t * exp(t0),
cos(t0) - t * sin(t0),
sin(t0) + t * cos(t0),
(t, 0, 1))
for t0 in range(-5, 6) if t0 != 0],
legend=False,
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.save('sample1.png')
p.show()

if __name__ == "__main__":
main()


% ./sample1.py -v
1, 2, 3, 4.
test1 (__main__.Test) ... ok
test2 (__main__.Test) ... ok
test3 (__main__.Test) ... ok
test4 (__main__.Test) ... ok

----------------------------------------------------------------------
Ran 4 tests in 0.013s

OK
%