## 2020年8月1日土曜日

### 数学 - Python - 解析学 - ベクトルの微分 - 微分係数 - 2曲線、交点、接線のなす角、指数関数、三角関数(正弦と余弦)、内積

1. $\begin{array}{l}{e}^{t}=1-\theta \\ {e}^{2t}=\mathrm{cos}\theta \\ 1-{e}^{-t}=\mathrm{sin}\theta \end{array}$
$\begin{array}{l}{e}^{t}=-1\\ 1=\mathrm{cos}\theta \\ \theta =0\\ 1-{e}^{-t}=0\\ t=0\end{array}$

よって、 2曲線は

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

で交わる。

$\frac{d}{\mathrm{dt}}\left({e}^{t},{e}^{2t},1-{e}^{-t}\right)=\left({e}^{t},2{e}^{2t},{e}^{-t}\right)$
$\frac{d}{\mathrm{dt}}\left(1-\theta ,\mathrm{cos}\theta ,\mathrm{sin}\theta \right)=\left(-1,-\mathrm{sin}\theta ,\mathrm{cos}\theta \right)$
$\left({e}^{t},2{e}^{2t},{e}^{-t}\right)·\left(-1,-\mathrm{sin}\theta ,\mathrm{cos}\theta \right)$
$=-{e}^{t}-2{e}^{2t}\mathrm{sin}\theta +{e}^{-t}\mathrm{cos}\theta$
$\begin{array}{l}t=0,\theta =0\\ -1+0+1=0\end{array}$

よって、接線の間の角の余弦は

$0$

よって、求める角は

$\frac{\pi }{2}$

コード

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

print('18.')

t, theta = symbols('t, θ', real=True)
x1 = Matrix([exp(t), exp(2 * t), 1 - exp(-t)])
x2 = Matrix([1 - theta, cos(theta), sin(theta)])
x11 = Derivative(x1, t, 1).doit()
x21 = Derivative(x2, theta, 1).doit()
t0 = 0
theta0 = solve((x1 - x2).subs({t: t0}), theta)[0][0]

class Test(TestCase):
def test1(self):
self.assertEqual(x1.subs({t: t0}), x2.subs({theta: theta0}))

def test2(self):
a = x11.subs({t: t0})
b = x21.subs({theta: theta0})
self.assertEqual(a.dot(b) / (a.norm() * b.norm()), 0)

colors = ['red', 'green', 'blue', 'brown', 'orange',
'purple', 'pink', 'gray', 'skyblue', 'yellow']
p = plot3d_parametric_line(
(*x1, (t, -1, 1)),
(*x2.subs({theta: t}), (t, -1, 1)),
(*(x1.subs({t: t0}) + t * x11.subs({t: t0})), (t, 0, 1)),
(*(x2.subs({theta: theta0}) + t * x21.subs({theta: theta0})), (t, 0, 1)),
show=False,
legend=False,
)
for o, color in zip(p, colors):
o.line_color = color
p.save(f'sample18.png')
p.show()

if __name__ == "__main__":
main()


% ./sample18.py -v
18.
/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/numpy/ma/core.py:2831: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray
_data = np.array(data, dtype=dtype, copy=copy,
test1 (__main__.Test) ... ok
test2 (__main__.Test) ... ok

----------------------------------------------------------------------
Ran 2 tests in 0.003s

OK
%