学習環境
- Surface
- Windows 10 Pro (OS)
- Nebo(Windowsアプリ)
- iPad
- MyScript Nebo - MyScript(iPadアプリ(iOS))
- 参考書籍
新装版 数学読本3 (松坂 和夫(著)、岩波書店)の第9章(図形と代数の交錯する世界 - 平面上のベクトル)、9.1(ベクトルとその演算)、平行四辺形の面積の問22の解答を求めてみる。
コード
#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import Matrix, Rational
print('22.')
def s(a, b, c):
v = b - a
w = c - a
return Rational(abs(v[0] * w[1] - v[1] * w[0]), 2)
class MyTestCase(TestCase):
def test1(self):
a = Matrix([0, 0])
b = Matrix([3, 4])
c = Matrix([1, -2])
self.assertEqual(s(a, b, c), 5)
def test2(self):
a = Matrix([2, 1])
b = Matrix([-1, 3])
c = Matrix([3, 6])
self.assertEqual(s(a, b, c), Rational(17, 2))
if __name__ == "__main__":
main()
入出力結果(Zsh、PowerShell、Terminal、Jupyter(IPython))
% ./sample22.py -v
22.
test1 (__main__.MyTestCase) ... ok
test2 (__main__.MyTestCase) ... ok
----------------------------------------------------------------------
Ran 2 tests in 0.001s
OK
%
0 コメント:
コメントを投稿