数学のブログ

ベクトルの微分 曲線の長さ、スパイラル、三角関数(正弦と余弦)、2倍角、4倍角、速度ベクトル、積分

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

d dt ( cos 2 t , sin 2 t , 3 t )
= ( - 2 sin 2 t , 2 cos 2 t , 3 )
1 3 4 sin 2 2 t + 4 cos 2 2 t + 9 dt
= 1 3 13 dt
= 2 13

ここから

0 π 8 ( 4 sin 4 t , 4 cos 4 t , 1 ) dt
= 0 π 8 16 + 1 dt
= π 17 8

コード

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

print('2.')

X = Matrix([cos(2 * t), sin(2 * t), 3 * t])
X1 = Derivative(X, t, 1).doit()
ts1 = (1, 3)
Y = Matrix([cos(4 * t), sin(4 * t), t])
Y1 = Derivative(Y, t, 1).doit()
ts2 = (0, pi / 8)


class Test(TestCase):
    def test_a(self):
        self.assertEqual(
            Integral(X1.norm(), (t, *ts1)).doit().simplify(),
            2 * sqrt(13)
        )

    def test_b(self):
        self.assertEqual(
            Integral(Y1.norm(), (t, *ts2)).doit(),
            pi * sqrt(17) / 8
        )


p = plot3d_parametric_line(
    (*X, (t, -5, 1)),
    (*X, (t, 1, 3)),
    (*X, (t, 3, 5)),
    (*Y, (t, -5, 0)),
    (*Y, (t, 0, pi / 8)),
    (*Y, (t, pi / 8, 5)),
    show=False)
colors = ['red', 'green', 'blue', 'brown', 'orange',
          'purple', 'pink', 'gray', 'skyblue', 'yellow']
for o, color in zip(p, colors):
    o.line_color = color
    print(o, color)
p.xlabel = 'x'
p.ylabel = 'y'
p.save('sample2.png')
p.show()

if __name__ == "__main__":
    main()

入出力結果

% ./sample2.py -v
2.
3D parametric cartesian line: (cos(2*t), sin(2*t), 3*t) for t over (-5.0, 1.0) red
3D parametric cartesian line: (cos(2*t), sin(2*t), 3*t) for t over (1.0, 3.0) green
3D parametric cartesian line: (cos(2*t), sin(2*t), 3*t) for t over (3.0, 5.0) blue
3D parametric cartesian line: (cos(4*t), sin(4*t), t) for t over (-5.0, 0.0) brown
3D parametric cartesian line: (cos(4*t), sin(4*t), t) for t over (0.0, 0.39269908169872414) orange
3D parametric cartesian line: (cos(4*t), sin(4*t), t) for t over (0.39269908169872414, 5.0) purple
test_a (__main__.Test) ... ok
test_b (__main__.Test) ... ok

----------------------------------------------------------------------
Ran 2 tests in 1.027s

OK
%