学習環境
- Surface
- Windows 10 Pro (OS)
- Nebo(Windows アプリ)
- iPad
- MyScript Nebo - MyScript(iPad アプリ(iOS))
- 参考書籍
続 解析入門 (原書第2版) (S.ラング(著)、松坂 和夫(翻訳)、片山 孝次(翻訳)、岩波書店)の第1章(ベクトル)、5(パラメーター表示された直線)の練習問題1、2、3の解答を求めてみる。
コード
#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import symbols, Matrix, solve
from sympy.plotting import plot3d_parametric_line
from sympy.abc import t
print('1, 2, 3.')
fs = [Matrix([1, 3, -1]) + t * Matrix([5, 2, -3]),
Matrix([-1, 5, 3]) + t * Matrix([1, 1, -4]),
Matrix([1, 1, -1]) + t * Matrix([3, 0, -4]),
Matrix([-1, 5, 2]) + t * Matrix([4, -9, -1])]
class Test(TestCase):
def test1a(self):
self.assertEqual(
len(solve(fs[0] - Matrix([1, 3, -1]))),
1
)
self.assertEqual(
len(solve(fs[0] - Matrix([-4, 1, 2]))),
1
)
def test1b(self):
self.assertEqual(
len(solve(fs[1] - Matrix([-1, 5, 3]))),
1
)
self.assertEqual(
len(solve(fs[1] - Matrix([-2, 4, 7]))),
1
)
def test2(self):
self.assertEqual(
len(solve(fs[2] - Matrix([1, 1, -1]))),
1
)
self.assertEqual(
len(solve(fs[2] - Matrix([-2, 1, 3]))),
1
)
def test3(self):
self.assertEqual(
len(solve(fs[3] - Matrix([-1, 5, 2]))),
1
)
self.assertEqual(
len(solve(fs[3] - Matrix([3, -4, 1]))),
1
)
p = plot3d_parametric_line(*[(*f, (t, -5, 5))
for f in fs],
legend=True,
show=False)
colors = ['red', 'green', 'blue', 'brown', 'orange',
'purple', 'pink', 'gray', 'skyblue', 'yellow']
for o, color in zip(p, colors):
o.line_color = color
p.show()
p.save('sample1.png')
if __name__ == "__main__":
main()
入出力結果(Zsh、PowerShell、Terminal、Jupyter(IPython))
% ./sample1.py -v
1, 2, 3.
test1a (__main__.Test) ... ok
test1b (__main__.Test) ... ok
test2 (__main__.Test) ... ok
test3 (__main__.Test) ... ok
----------------------------------------------------------------------
Ran 4 tests in 0.031s
OK
%
0 コメント:
コメントを投稿