2019年12月11日水曜日

学習環境

ラング線形代数学(上) (ちくま学現文庫)(S.ラング (著)、芹沢 正三 (翻訳)、筑摩書房)の1章(R^nにおけるベクトル)、5(直線と平面)、練習問題20の解答を求めてみる。


  1. 平面

    3 x + y - 5 z = 2

    に垂直なベクトル(法線ベクトル)は

    N = 3 , 1 , - 5

    点(1,1,2) を通り N の向きを持つ直線のパラメーター方程式は、

    x , y , z = 1 , 1 , 2 + t 3 , 1 , - 5 = 1 + 3 t , 1 + t , 2 - 5 t

    この直線と平面との交点は、

    3 1 + 3 t + 1 + t - 5 2 - 5 t = 2 3 + 9 t + 1 + t - 10 + 25 t = 2 35 t = 8 t = 8 35 1 + 3 · 8 35 , 1 + 8 35 , 2 - 5 · 8 35 = 59 35 , 43 35 , 30 35

    よって、 求める点と平面の距離は、

    59 35 - 1 2 + 43 35 - 1 2 + 30 35 - 2 2 = 2 4 2 + 8 2 + 4 0 2 35 = 2240 35 = 8 35 35 = 8 35

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import pprint, symbols, sqrt
from sympy.plotting import plot3d, plot3d_parametric_line

print('20.')


class MyTestCase(TestCase):
    def test(self):
        self.assertEqual(sqrt(2240) / 35, 8 / sqrt(35))
        self.assertEqual(abs(3 * 1 + 1 - 5 * 2 - 2) /
                         sqrt(3 ** 2 + 1 ** 2 + 5 ** 2), 8 / sqrt(35))


x, y, t = symbols('x, y, t')
p = plot3d_parametric_line(1 + 3 * t, 1 + t, 2 - 5 * t, show=False)
p1 = plot3d((3 * x + y - 2) / 5, show=False)
p.append(p1[0])
p.xlabel = x
p.ylabel = y
p.show()
p.save('sample20.png')


if __name__ == '__main__':
    main()

入出力結果(Zsh、cmd.exe(コマンドプロンプト)、Terminal、Jupyter(IPython))

% ./sample20.py -v
20.
test (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.003s

OK
%

0 コメント:

コメントを投稿