学習環境
ラング線形代数学(上)
(ちくま学現文庫 )(S.ラング
(著)、芹沢
正三 (翻訳)、筑摩書房 )の1章(R^nにおけるベクトル)、5(直線と平面)、練習問題21の解答を求めてみる。
コード
#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import symbols, Rational
from sympy.plotting import plot3d_parametric_line
print ('21.' )
p0 = (1 , 3 , -1 )
q0 = (-4 , 5 , 2 )
class MyTestCase (TestCase):
def test_a (self ):
self . assertEqual(tuple ([Rational(a0 + b0, 2 ) for a0, b0 in zip (p0, q0)]),
(- Rational(3 , 2 ), 4 , Rational(1 , 2 )))
def test_b1 (self ):
self . assertEqual(tuple ([Rational(2 * a0 + b0, 3 ) for a0, b0 in zip (p0, q0)]),
(- Rational(2 , 3 ), Rational(11 , 3 ), 0 ))
def test_b2 (self ):
self . assertEqual(tuple ([Rational(a0 + 2 * b0, 3 ) for a0, b0 in zip (p0, q0)]),
(- Rational(7 , 3 ), Rational(13 , 3 ), 1 ))
t, x, y = symbols('t, x, y' )
p = plot3d_parametric_line(1 - 5 * t, 3 + 2 * t, -1 + 3 * t, show= False )
p. xlabel = x
p. ylabel = y
p. show()
p. save('sample21.png' )
if __name__ == '__main__' :
main()
入出力結果(Zsh、cmd.exe(コマンドプロンプト)、Terminal、Jupyter(IPython))
% ./sample21.py -v
21.
test_a (__main__.MyTestCase) ... ok
test_b1 (__main__.MyTestCase) ... ok
test_b2 (__main__.MyTestCase) ... ok
----------------------------------------------------------------------
Ran 3 tests in 0.001s
OK
%
0 コメント:
コメントを投稿