2020年6月28日日曜日

数学 - Pytyhon - 解析学 - ベクトル - 平面 - 4次元、パラメーター直線、点との距離、最小値、垂直、内積、零

1. $\begin{array}{l}X=\left(1,-1,3,1\right)+t\left(1,-3,2,1\right)\\ =\left(1+t,-1-3t,3+2t,1+t\right)\end{array}$
$\begin{array}{l}|QX|=\sqrt{{t}^{2}+{\left(-3t-2\right)}^{2}+{\left(2t+4\right)}^{2}+{\left(t-1\right)}^{2}}\\ =\sqrt{15{t}^{2}+26t+21}\end{array}$

2. $\begin{array}{l}15{t}^{2}+26t+21\\ =15{\left({t}^{2}+\frac{26}{15}t\right)}^{2}+21\\ =14{\left(t+\frac{13}{15}\right)}^{2}-\frac{1{3}^{2}}{15}+21\\ =14{\left(t+\frac{13}{15}\right)}^{2}+\frac{146}{15}\end{array}$

よって求める距離の最小値は

$\sqrt{\frac{146}{15}}$

3. ${X}_{0}=\left(1-\frac{13}{15},-1+\frac{39}{15},3-\frac{26}{15},1-\frac{13}{15}\right)$
$\begin{array}{l}{X}_{0}-Q=\left(-\frac{13}{15},-2+\frac{39}{15},4-\frac{26}{15},-1-\frac{13}{15}\right)\\ =\left(-\frac{13}{15},\frac{9}{15},\frac{34}{15},-\frac{28}{15}\right)\end{array}$
$\begin{array}{l}\left({X}_{0}-Q\right)·A\\ =\frac{1}{15}\left(-13,9,34,-28\right)·\left(1,-3,2,1\right)\\ =\frac{1}{15}\left(-13-27+68-28\right)\\ =0\end{array}$

よって垂直である。

（証明終）

コード

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

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
x0 = Matrix([1 - Rational(13, 15),
-1 + Rational(39, 15),
3 - Rational(26, 15),
1 - Rational(13, 15)])

class Test(TestCase):
def test_a(self):
self.assertEqual((l - q).norm().simplify(),
sqrt(15 * t ** 2 + 26 * t + 21))

def test_c(self):
self.assertEqual((x0 - q).dot(a), 0)

if __name__ == "__main__":
main()


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

----------------------------------------------------------------------
Ran 2 tests in 0.278s

OK
%