ベクトルの微分 曲線の長さ、三角関数、正弦と余弦、加法定理、倍角、速度ベクトル、積分
続 解析入門 (原書第2版) (S.ラング(著)、松坂 和夫(翻訳)、片山 孝次(翻訳)、岩波書店)の第2章(ベクトルの微分)、2(曲線の長さ)の練習問題4-a、b.の解答を求めてみる。
求める曲線の長さ。
ここから
コード
#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import Matrix, Derivative, sin, cos, Integral, pi, sqrt
from sympy import Rational
from sympy.plotting import plot_parametric
from sympy.abc import t
print('4.')
X = Matrix([t - sin(t), 1 - cos(t)])
X1 = Derivative(X, t, 1).doit()
class Test(TestCase):
def test_a(self):
self.assertEqual(
Integral(2 * sqrt(sin(t / 2) ** 2), (t, 0, 2 * pi)).doit(),
8
)
def test_b(self):
self.assertEqual(
Integral(2 * sqrt(sin(t / 2) ** 2), (t, 3, 5)).doit(),
4 * (cos(Rational(3, 2)) - cos(Rational(5, 2)))
)
p = plot_parametric(
(*X, (t, -pi, 0)),
(*X, (t, 0, 2 * pi)),
(*X, (t, 2 * pi, 3 * pi)),
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.save('sample4_a.png')
p = plot_parametric(
(*X, (t, 2, 3)),
(*X, (t, 3, 5)),
(*X, (t, 5, 6)),
show=False,
)
for o, color in zip(p, colors):
o.line_color = color
print(o, color)
p.save('sample4_b.png')
p.show()
if __name__ == "__main__":
main()
入出力結果
% ./sample4.py -v
4.
parametric cartesian line: (t - sin(t), 1 - cos(t)) for t over (-3.141592653589793, 0.0) red
parametric cartesian line: (t - sin(t), 1 - cos(t)) for t over (0.0, 6.283185307179586) green
parametric cartesian line: (t - sin(t), 1 - cos(t)) for t over (6.283185307179586, 9.42477796076938) blue
parametric cartesian line: (t - sin(t), 1 - cos(t)) for t over (2.0, 3.0) red
parametric cartesian line: (t - sin(t), 1 - cos(t)) for t over (3.0, 5.0) green
parametric cartesian line: (t - sin(t), 1 - cos(t)) for t over (5.0, 6.0) blue
test_a (__main__.Test) ... ok
test_b (__main__.Test) ... ok
----------------------------------------------------------------------
Ran 2 tests in 0.671s
OK
%