2020年1月25日土曜日

学習環境

新装版 数学読本3 (松坂 和夫(著)、岩波書店)の第9章(図形と代数の交錯する世界 - 平面上のベクトル)、9.1(ベクトルとその演算)、ベクトルの成分の問8の解答を求めてみる。



    1. m-4,3+n1,-3=0,-9-4m+n,3m-3n=0,-9{-4m+n=03m-3n=-9{-4m+n=0m-n=-3-3m=-3m=1n=1+3=4

      よって、

      c=a+4b

    2. {-4m+n=133m-3n=-21{-4m+n=13m-n=-7-3m=6m=-2n=-2+7=5d=-2a+5b

コード

#!/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()

入出力結果(Zsh、PowerShell、Terminal、Jupyter(IPython))

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

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

OK
%

0 コメント:

コメントを投稿