## 2020年1月25日土曜日

### 数学 - Python - 図形と代数の交錯する世界 - 平面上のベクトル - ベクトルとその演算 - ベクトルの成分 - 2つのベクトル、実数倍と和

1. $\begin{array}{l}m\left(-4,3\right)+n\left(1,-3\right)=\left(0,-9\right)\\ \left(-4m+n,3m-3n\right)=\left(0,-9\right)\\ \left\{\begin{array}{l}-4m+n=0\\ 3m-3n=-9\end{array}\\ \left\{\begin{array}{l}-4m+n=0\\ m-n=-3\end{array}\\ -3m=-3\\ m=1\\ n=1+3=4\end{array}$

よって、

$\stackrel{\to }{c}=\stackrel{\to }{a}+4\stackrel{\to }{b}$

2. $\begin{array}{l}\left\{\begin{array}{l}-4m+n=13\\ 3m-3n=-21\end{array}\\ \left\{\begin{array}{l}-4m+n=13\\ m-n=-7\end{array}\\ -3m=6\\ m=-2\\ n=-2+7=5\\ \stackrel{\to }{d}=-2\stackrel{\to }{a}+5\stackrel{\to }{b}\end{array}$

コード

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

print('8.')

a = Matrix([-4, 3])
b = Matrix([1, -3])
m, n = symbols('m, n', real=True)
v = m * a + n * b

class MyTestCase(TestCase):
def test1(self):
c = Matrix([0, -9])
self.assertEqual(solve(v - c), {m: 1, n: 4})

def test2(self):
d = Matrix([13, -21])
self.assertEqual(solve(v - d), {m: -2, n: 5})

if __name__ == '__main__':
main()


% ./sample8.py -v
8.
test1 (__main__.MyTestCase) ... ok
test2 (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 2 tests in 0.019s

OK
%