学習環境
- Surface
- Windows 10 Pro (OS)
- Nebo(Windows アプリ)
- iPad
- MyScript Nebo - MyScript(iPad アプリ(iOS))
- 参考書籍
解析入門 原書第3版 (S.ラング(著)、松坂 和夫(翻訳)、片山 孝次(翻訳)、岩波書店)の第Ⅵ部(多変数の関数)、第17章(ベクトル)、5(直線と平面)の練習問題21の解答を求めてみる。
コード
#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import symbols, Matrix, Rational
from sympy.plotting import plot3d_parametric_line
print('21.')
p = Matrix([1, 3, -1])
q = Matrix([-4, 5, 2])
pq = q - p
class MyTestCase(TestCase):
def test_a(self):
self.assertEqual(
(p + q) / 2, Matrix([-Rational(3, 2), 4, Rational(1, 2)]))
def test_b(self):
self.assertEqual(
p + pq / 3, Matrix([-Rational(2, 3), Rational(11, 3), 0]))
self.assertEqual(
p + 2 * pq / 3, Matrix([-Rational(7, 3), Rational(13, 3), 1]))
def test_c(self):
self.assertEqual(
p + pq / 5, Matrix([0, Rational(17, 5), -Rational(2, 5)]))
def test_d(self):
self.assertEqual(
p + 2 * pq / 5, Matrix([-1, Rational(19, 5), Rational(1, 5)]))
t = symbols('t')
p0 = plot3d_parametric_line(*(p + t * pq), legend=True, show=False)
colors = ['red', 'green', 'blue', 'brown', 'orange',
'purple', 'pink', 'gray', 'skyblue', 'yellow']
for s, color in zip(p0, colors):
s.line_color = color
p0.show()
p0.save('sample21.png')
if __name__ == "__main__":
main()
入出力結果(Zsh、PowerShell、Terminal、Jupyter(IPython))
% ./sample21.py -v
21.
test_a (__main__.MyTestCase) ... ok
test_b (__main__.MyTestCase) ... ok
test_c (__main__.MyTestCase) ... ok
test_d (__main__.MyTestCase) ... ok
----------------------------------------------------------------------
Ran 4 tests in 0.002s
OK
%
0 コメント:
コメントを投稿