2020年1月29日水曜日

学習環境

解析入門 原書第3版 (S.ラング(著)、松坂 和夫(翻訳)、片山 孝次(翻訳)、岩波書店)の第Ⅵ部(多変数の関数)、第17章(ベクトル)、5(直線と平面)の練習問題11の解答を求めてみる。



    1. 点 P を 通り、ベクトル A に平行な直線のパラメーター方程式は、

      L=1,-1,3,1+t1,-3,2,1=1+t,-1-3t,3+2t,1+t

      Q と L 上の点 X との距離は、

      1-1+t2+1--1-3t2+-1-3+2t2+2-1+t2=t2+2+3t2+-4-2t2+1-t2=t2+9t2+12t+4+4t2+16t+16+1-2t+t2=15t2+26t+21

    2. 15t2+26t+21=15t2+2615t+21=15t+13152+14615

      よって、 距離が最小となるのは

      t=-1315

      のとき、ちなか でのような点は直線上にただ1つ存在し、この値は

      14615

      である。


    3. X0-Q·A=-1315,-2+3915,4-2615,-1-1315·1,-3,2,1=-1315,915,3415,-2815·1,-3,2,1=115-13-27+68-28=0

      よって 垂直である。

      (証明終)

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import symbols, Matrix, sqrt, Rational, plot

print('11.')

p = Matrix([1, -1, 3, 1])
q = Matrix([1, 1, -1, 2])
a = Matrix([1, -3, 2, 1])
t = symbols('t', real=True)
l = p + t * a
distance = (q - l).norm()
t0 = -Rational(13, 15)


class MyTestCase(TestCase):
    def test_a(self):
        self.assertEqual((distance ** 2).expand(),
                         (15 * t ** 2 + 26 * t + 21).expand())

    def test_b(self):
        self.assertEqual(distance.subs({t: t0}), sqrt(Rational(146, 15)))

    def test_c(self):
        self.assertEqual((l.subs({t: t0}) - q).dot(a), 0)


p = plot(distance,
         sqrt(Rational(146, 15)),
         (t, -5, 5),
         ylim=(0, 10),
         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.show()
p.save(f'sample11.png')

if __name__ == "__main__":
    main()

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

% ./sample11.py -v
11.
test_a (__main__.MyTestCase) ... ok
test_b (__main__.MyTestCase) ... ok
test_c (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 3 tests in 0.009s

OK
%

0 コメント:

コメントを投稿