2019年12月11日水曜日

学習環境

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


  1. 平面

    3x+y-5z=2

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

    N=3,1,-5

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

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

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

    31+3t+1+t-52-5t=23+9t+1+t-10+25t=235t=8t=8351+3·835,1+835,2-5·835=5935,4335,3035

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

    5935-12+4335-12+3035-22=242+82+40235=224035=83535=835

コード

#!/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 コメント:

コメントを投稿