学習環境
新装版
数学読本3 (松坂
和夫 (著)、岩波書店 )の第9章(図形と代数の交錯する世界
- 平面上のベクトル)、9.1(ベクトルとその演算)、ベクトルの内積の問14の解答を求めてみる。
よって、 問題の等式が成り立つのは、2つのベクトルが同じ向きの場合。
よって、 等式が成り立つのは、2つのベクトルが逆向きの場合。
コード
#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import symbols, cos, solveset, Matrix, Interval, pi, FiniteSet
print ('14.' )
a1, a2, b1, b2, theta = symbols('a1, a2, b1, b2, theta' , real= True )
a = Matrix([a1, a2])
b = Matrix([b1, b2])
def dot (a, b):
return a. norm() * b. norm() * cos(theta)
class MyTestCase (TestCase):
def test_1 (self ):
s = solveset(dot(a, b) - a. norm() * b. norm(),
theta, domain= Interval(0 , pi))
self . assertEqual(s, FiniteSet(0 ))
def test_2 (self ):
s = solveset(dot(a, b) + a. norm() * b. norm(),
theta, domain= Interval(0 , pi))
self . assertEqual(s, FiniteSet(pi))
if __name__ == "__main__" :
main()
入出力結果(Zsh、PowerShell、Terminal、Jupyter(IPython))
% ./sample14.py -v
14.
test_1 (__main__.MyTestCase) ... ok
test_2 (__main__.MyTestCase) ... ok
----------------------------------------------------------------------
Ran 2 tests in 0.197s
OK
%
0 コメント:
コメントを投稿