学習環境
- Surface
- Windows 10 Pro (OS)
- Nebo(Windows アプリ)
- iPad
- MyScript Nebo - MyScript(iPad アプリ(iOS))
- 参考書籍
解析入門 原書第3版 (S.ラング(著)、松坂 和夫(翻訳)、片山 孝次(翻訳)、岩波書店)の第Ⅵ部(多変数の関数)、第17章(ベクトル)、5(直線と平面)の練習問題20の解答を求めてみる。
平面
の法線ベクトル(垂直なベクトル)の1つは
また、
は平面上の1点である。
よって求める点と平面の距離は
コード
#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import symbols, Matrix, sqrt
from sympy.plotting import plot3d
print('20.')
def distance(p, q, n):
return abs((q - p).dot(n)) / n.norm()
class MyTestCase(TestCase):
def test_a(self):
p = Matrix([1, 1, 2])
n = Matrix([3, 1, -5])
x, y, z = 0, 2, 0
self.assertEqual(3 * x + y - 5 * z, 2)
q = Matrix([x, y, z])
self.assertEqual(distance(p, q, n), 8 / sqrt(35))
def test_b(self):
p = Matrix([-1, 3, 2])
n = Matrix([2, -4, 1])
x, y, z = 0, 0, 1
self.assertEqual(2 * x - 4 * y + z, 1)
q = Matrix([x, y, z])
self.assertEqual(distance(p, q, n), 13 / sqrt(21))
x, y = symbols('x, y')
p = plot3d((3 * x + y - 2) / 5,
-2 * x + 4 * y + 1,
show=False)
colors = ['red', 'green', 'blue', 'brown', 'orange',
'purple', 'pink', 'gray', 'skyblue', 'yellow']
for s, color in zip(p, colors):
s.line_color = color
p.show()
p.save('sample20.png')
if __name__ == "__main__":
main()
入出力結果(Zsh、PowerShell、Terminal、Jupyter(IPython))
% ./sample20.py -v
20.
test_a (__main__.MyTestCase) ... ok
test_b (__main__.MyTestCase) ... ok
----------------------------------------------------------------------
Ran 2 tests in 0.005s
OK
%
0 コメント:
コメントを投稿