## 2020年2月13日木曜日

### 数学 - Python - 解析学 - 多変数の関数 - ベクトルの微分 - 微分係数 - パラメーター表示による曲線、速度ベクトル

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

2. $\left(2\mathrm{cos}2t,\frac{1}{1+t},1\right)$

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

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

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import Matrix, exp, sin, cos, symbols, Derivative, log
from sympy.plotting import plot_parametric, plot3d_parametric_line
print('1, 2, 3, 4.')

t = symbols('t')

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

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

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

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

p1 = plot3d_parametric_line(exp(t), cos(t), sin(t), show=False, legend=True)
p1.save('sample1_1.png')

p2 = plot3d_parametric_line(sin(2 * t), log(1 + t),
t, (t, -0.9, 10), show=False, legend=True)
p2.save('sample1_2.png')

p3 = plot_parametric(cos(t), sin(t), legend=True, show=False)
p3.save('sample1_3.png')

p4 = plot_parametric(cos(3 * t), sin(3 * t), legend=True, show=False)
p4.save('sample1_4.png')

if __name__ == "__main__":
main()


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

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

OK
%