## 2020年2月7日金曜日

### 数学 - Python - 図形と代数の交錯する世界 - 平面上のベクトル - ベクトルとその演算 - 内積を成分で表すこと - 垂直

1. $\begin{array}{l}\stackrel{\to }{a}·\left(\stackrel{\to }{a}+x\stackrel{\to }{b}\right)\\ =\stackrel{\to }{a}·\stackrel{\to }{a}+x\left(\stackrel{\to }{a}·\stackrel{\to }{b}\right)\\ ={\left|\stackrel{\to }{a}\right|}^{2}+x\left(\stackrel{\to }{a}·\stackrel{\to }{b}\right)\\ ={\left|\left(2,3\right)\right|}^{2}+x\left(2,3\right)·\left(1,-1\right)\\ =13+x\left(2-3\right)\\ =13-x\\ 13-x=0\\ x=13\end{array}$

2. $\begin{array}{l}\left(1,4\right)·\left(2+x,3-x\right)=0\\ 2+x+12-4x=0\\ x=\frac{14}{3}\end{array}$

3. $\begin{array}{l}\left(\stackrel{\to }{a}+x\stackrel{\to }{b}\right)·\left(\stackrel{\to }{a}-x\stackrel{\to }{b}\right)=0\\ {\left|\stackrel{\to }{a}\right|}^{2}-{x}^{2}{\left|\stackrel{\to }{b}\right|}^{2}=0\\ 4+9-{x}^{2}\left(1+1\right)=0\\ {x}^{2}=\frac{13}{2}\\ x=±\sqrt{\frac{13}{2}}\end{array}$

コード

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

print('17.')

a = Matrix([2, 3])
b = Matrix([1, -1])
x = symbols('x')

class MyTestCase(TestCase):
def test1(self):
self.assertEqual(solveset(a.dot(a + x * b)), {13})

def test2(self):
self.assertEqual(solveset((a - b).dot(a + x * b)), {Rational(14, 3)})

def test3(self):
self.assertEqual(solveset((a + x * b).dot(a - x * b)),

if __name__ == "__main__":
main()

% ./sample17.py -v
17.
test1 (__main__.MyTestCase) ... ok
test2 (__main__.MyTestCase) ... ok
test3 (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 3 tests in 0.099s

OK
%