2020年7月28日火曜日

学習環境

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


  1. v ( t ) = X ' ( t ) = X ' ( t ) · X ' ( t )
    v ( t ) 2 = X ' ( t ) · X ' ( t )
    d dt ( v ( t ) 2 ) = 2 X ' ( t ) · X ' ' ( t ) = 0

    よって、

    v ( t ) 2

    は一定、 すなわち速度

    v ( t )

    は一定である。

    (証明終)

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import Matrix, sin, cos, pi, Derivative, pprint
from sympy.plotting import plot_parametric
from sympy.abc import t

print('14.')
x = Matrix([cos(t), sin(t)])
x1 = Derivative(x, t, 1).doit()
x2 = Derivative(x, t, 2).doit()


class Test(TestCase):
    def test(self):
        self.assertEqual(x1.dot(x2), 0)


t0 = 1
xt0 = x.subs({t: t0})
x1t0 = x1.subs({t: t0})
x2t0 = x2.subs({t: t0})
p = plot_parametric(
    (*x, (t, 0, 2 * pi)),
    (xt0[0] + t * x1t0[0], xt0[1] + t * x1t0[1], (t, 0, 1)),
    (xt0[0] + t * x2t0[0], xt0[1] + t * x2t0[1], (t, 0, 1)),
    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.save('sample14.png')
p.show()

if __name__ == "__main__":
    main()

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

% ./sample14.py -v
14.
test (__main__.Test) ... ok

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

OK
%

0 コメント:

コメントを投稿