2020年6月4日木曜日

学習環境

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



    1. 2点

      1 , 2 , 3 , 3 , 1 , - 5

      を通る直線の方程式を求める。

      x , y , z = 1 , 2 , 3 + t 2 , - 1 , - 8

      xy 平面と の交点の z 座標.は0なので

      3 - 8 t = 0 t = 3 8

      よって、求める交点の座標_は

      1 , 2 , 3 + 3 8 2 , - 1 , - 8 = 1 , 2 , 3 + 3 4 , - 3 8 , - 3 = 7 4 , 13 8 , 0

    2. 2 - t = 0 t = 2
      1 , 2 , 3 + 2 2 , - 1 , - 8 = 5 , 0 , - 13

    3. x , y , z = - 1 , 2 , 3 + t 4 , 0 , 7 = - 1 + 4 t , 2 , 3 + 7 t
      - 1 + 4 t - 4 · 2 + 4 3 + 7 t = 19 32 t = 16 t = 1 2
      - 1 + 2 , 2 , 3 + 7 2 = 1 , 2 , 13 2

    4. x = 1 + t y = - 1 + 4 t z = - 2 - t
      2 + 2 t - 2 + 8 t - 2 - t = 7 9 t = 9 t = 1
      2 , 3 , - 3

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import Matrix, solve, Rational
from sympy.abc import x, y, z, t

print('30.')

ls = [Matrix([1, 2, 3]) + t * (Matrix([3, 1, -5]) - Matrix([1, 2, 3])),
      Matrix([-1, 2, 3]) + t * Matrix([4, 0, 7]),
      Matrix([1, -1, -2]) + t * Matrix([1, 4, -1])]


class Test(TestCase):
    def test1(self):
        t0 = solve(ls[0][2], t)[0]
        self.assertEqual(ls[0].subs({t: t0}),
                         Matrix([Rational(7, 4), Rational(13, 8), 0]))

    def test2(self):
        t0 = solve(ls[0][1], t)[0]
        self.assertEqual(ls[0].subs({t: t0}),
                         Matrix([5, 0, -13]))

    def test3(self):
        t0 = solve(
            (x - 4 * y + 4 * z - 19).subs(dict(zip([x, y, z], ls[1]))))[0]
        self.assertEqual(ls[1].subs({t: t0}),
                         Matrix([1, 2, Rational(13, 2)]))

    def test4(self):
        t0 = solve(
            (2 * x + 2 * y + z - 7).subs({x: 1 + t, y: -1 + 4 * t, z: -2 - t}))[0]
        self.assertEqual(ls[2].subs({t: t0}),
                         Matrix([2, 3, -3]))


if __name__ == "__main__":
    main()

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

% ./sample30.py -v 
30.
test1 (__main__.Test) ... ok
test2 (__main__.Test) ... ok
test3 (__main__.Test) ... ok
test4 (__main__.Test) ... ok

----------------------------------------------------------------------
Ran 4 tests in 0.019s

OK
%

0 コメント:

コメントを投稿