2020年1月28日火曜日

学習環境

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


  1. p = a + t b = 8 , - 2 + t 0 , 2 = 8 , - 2 + 2 t = 2 3 , 2 t - 1 = 2 6 + 2 2 t - 1 2 = 2 2 4 + t - 1 2 = 2 t 2 - 2 t + 17

    これが 10になるには、

    2 t 2 - 2 t + 17 = 10 t 2 - 2 t + 17 = 5 t 2 - 2 t + 17 = 25 t 2 - 2 t - 8 = 0 t - 4 t + 2 = 0 t = - 2 , 4

コード

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

print('11.')

t = symbols('t')

a = Matrix([8, -2])
b = Matrix([0, 2])
p = a + t * b


class MyTestCase(TestCase):
    def test1(self):
        self.assertEqual(p.subs({t: -2}).norm(), 10)

    def test2(self):
        self.assertEqual(p.subs({t: 4}).norm(), 10)


if __name__ == "__main__":
    main()

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

% ./sample11.py -v
11.
test1 (__main__.MyTestCase) ... ok
test2 (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 2 tests in 0.004s

OK
%

0 コメント:

コメントを投稿