## 2020年3月2日月曜日

### 数学 - Python - 解析学 - 多変数の関数 - ベクトルの微分 - 微分係数 - 曲線、接線、z軸となす角、内積、ノルム、余弦

1. $\begin{array}{l}X\left(t\right)=\left(a\left(\mathrm{cos}t\right),a\left(\mathrm{sin}t\right),bt\right)\\ X\text{'}\left(t\right)=\left(-a\left(\mathrm{sin}t\right),a\left(\mathrm{cos}t\right),b\right)\end{array}$

よって、 曲線上の点 t における接線の向き は

$\left(-a\left(\mathrm{sin}t\right),a\left(\mathrm{cos}t\right),b\right)$

また z 軸の 向きは

$\left(0,0,1\right)$

よって、 接線と z 軸とのなす角の余弦は

$\begin{array}{l}\mathrm{cos}\left(\theta \left(t\right)\right)\\ =\frac{\left(-a\left(\mathrm{sin}t\right),a\left(\mathrm{cos}t\right),b\right)·\left(0,0,1\right)}{∥-a\left(\mathrm{sin}t\right),a\left(\mathrm{cos}t\right),b∥∥\left(0,0,1\right)∥}\\ =\frac{b}{\sqrt{{a}^{2}+{b}^{2}}}\end{array}$

（証明終）

コード

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

print('21.')

a = 2
b = 3
t = symbols('t')
x = Matrix([a * cos(t), a * sin(t), b * t])
x1 = Derivative(x, t, 1).doit()
ts = [-2, 3]
ls = [x.subs({t: t0}) + t * x1.subs({t: t0}) for t0 in [-2, 3]]
z = Matrix([0, 0, 1])

class MyTestCase(TestCase):
def test(self):
self.assertEqual(x1, Matrix([-a * sin(t), a * cos(t), b]))

p = plot3d_parametric_line(*[(*s, (t, -20, 20)) for s in [x] + ls],
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('sample21.png')

if __name__ == "__main__":
main()


% ./sample21.py -v
21.
test (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.001s

OK
%