2020年1月29日水曜日

学習環境

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



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

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

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

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

    2. 15 t 2 + 26 t + 21 = 15 t 2 + 26 15 t + 21 = 15 t + 13 15 2 + 146 15

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

      t = - 13 15

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

      146 15

      である。


    3. X 0 - Q · A = - 13 15 , - 2 + 39 15 , 4 - 26 15 , - 1 - 13 15 · 1 , - 3 , 2 , 1 = - 13 15 , 9 15 , 34 15 , - 28 15 · 1 , - 3 , 2 , 1 = 1 15 - 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 コメント:

コメントを投稿