2020年6月11日木曜日

学習環境

新装版 数学読本3 (松坂 和夫(著)、岩波書店)の第11章(立体的な広がりの中の図形 - 空間図形)、11.3(直線・平面・球の方程式)、点と平面の距離の問35の解答を求めてみる。



    1. 5 4 + 16 + 9 = 5 29

    2. | 3 - 2 + 8 + 3 | 1 + 4 + 4 = 12 3 = 4

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import symbols, sqrt, Matrix
from sympy.plotting import plot3d
from sympy.abc import x, y, z

print('35.')


class Test(TestCase):
    def test1(self):
        self.assertEqual(
            abs((2 * x - 4 * y + 3 * z - 5).subs({x: 0, y: 0, z: 0})) /
            Matrix([2, -4, 3]).norm(),
            5 / sqrt(29))

    def test2(self):
        self.assertEqual(
            abs((x - 2 * y + 2 * z + 3).subs({x: 3, y: 1, z: 4}))
            / Matrix([1, -2, 2]).norm(),
            4
        )


p = plot3d(-(2 * x - 4 * y - 5) / 3,
           -(x - 2 * y + 3) / 2,
           show=True)

p.save('sample35.png')

if __name__ == "__main__":
    main()

入出力結果(Zsh、PowerShell、Terminal、Jupyter(IPython))

% ./sample35.py -v
35.
test1 (__main__.Test) ... ok
test2 (__main__.Test) ... ok

----------------------------------------------------------------------
Ran 2 tests in 0.005s

OK
%

0 コメント:

コメントを投稿