Loading [MathJax]/jax/output/CommonHTML/jax.js

2018年11月16日金曜日

学習環境

ラング線形代数学(上)(S.ラング (著)、芹沢 正三 (翻訳)、ちくま学芸文庫)の1章(R^n におけるベクトル)、5(直線と平面)、練習問題8.を取り組んでみる。



    1. (x,y,z)=(2,1,1)+t(1,-2,0)+s(2,0,-2)x=2+t+2sy=1-2tz=1-2st=1-y2s=1-z2x=2+1-y2+1-z2x=4+1-y+2-2z2x+y+2z=7

    2. (x,y,z)=(-2,3,-1)+s(4,-1,4)+t(-2,-4,2)x=-2+4s-2ty=3-s-4tz=-1+4s+2tx+z=-3+8s2x-y=-7+9s9x+9z=-27+72516x-8y=-56+72s7x-8y-9z=-29

    3. (x,y,z)=(-5,-1,2)+s(6,3,-3)+t(8,0,0)x=-5+6s+8ty=-1+3sz=2-3sy+z=1

コード(Emacs)

Python 3

#!/usr/bin/env python3
from sympy import pprint, symbols, Matrix, solve

ps = [((2, 1, 1), (3, -1, 1), (4, 1, -1)),
      ((-2, 3, -1), (2, 2, 3), (-4, -1, 1)),
      ((-5, -1, 2), (1, 2, -1), (3, -1, 2))]

x = Matrix(symbols('x, y, z'))
s, t = symbols('s, t')
for i, (u, v, w) in enumerate(ps):
    print(f'({chr(ord("a") + i)})')
    a = Matrix(v) - Matrix(u)
    b = Matrix(w) - Matrix(u)
    eq = Matrix(u) + s * a + t * b - x
    st = solve(eq, dict=True)[0]
    s0, t0 = st[s], st[t]
    pprint(eq.subs({s: s0, t: t0}))

入出力結果(Terminal, Jupyter(IPython))

$ ./sample8.py
(a)
⎡     y       7⎤
⎢-x - ─ - z + ─⎥
⎢     2       2⎥
⎢              ⎥
⎢      0       ⎥
⎢              ⎥
⎣      0       ⎦
(b)
⎡     8⋅y   9⋅z   29⎤
⎢-x + ─── + ─── - ──⎥
⎢      7     7    7 ⎥
⎢                   ⎥
⎢         0         ⎥
⎢                   ⎥
⎣         0         ⎦
(c)
⎡    0     ⎤
⎢          ⎥
⎢-y - z + 1⎥
⎢          ⎥
⎣    0     ⎦
$

0 コメント:

コメントを投稿