2020年8月1日土曜日

学習環境

続 解析入門 (原書第2版) (S.ラング(著)、松坂 和夫(翻訳)、片山 孝次(翻訳)、岩波書店)の第2章(ベクトルの微分)、1(微分係数)の練習問題18の解答を求めてみる。


  1. e t = 1 - θ e 2 t = cos θ 1 - e - t = sin θ
    e t = - 1 1 = cos θ θ = 0 1 - e - t = 0 t = 0

    よって、 2曲線は

    ( 1 , 1 , 0 )

    で交わる。

    d dt ( e t , e 2 t , 1 - e - t ) = ( e t , 2 e 2 t , e - t )
    d dt ( 1 - θ , cos θ , sin θ ) = ( - 1 , - sin θ , cos θ )
    ( e t , 2 e 2 t , e - t ) · ( - 1 , - sin θ , cos θ )
    = - e t - 2 e 2 t sin θ + e - t cos θ
    t = 0 , θ = 0 - 1 + 0 + 1 = 0

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

    0

    よって、求める角は

    π 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()

入出力結果(Zsh、PowerShell、Terminal、Jupyter(IPython))

% ./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
%

0 コメント:

コメントを投稿