2018年6月21日木曜日

学習環境

ラング線形代数学(上)(S.ラング (著)、芹沢 正三 (翻訳)、ちくま学芸文庫)の7章(スカラー積と直交性)、3(一般の直交基底)、練習問題1-(a)、(b).を取り組んでみる。



    1. 1 , 1 , 1 1 , - 1 , 2 - 1 , - 1 , 2 · 1 , 1 , 1 1 , 1 , 1 · 1 , 1 , 1 1 , 1 , 1 = 1 , - 1 , 2 - 1 - 2 + 2 1 + 2 + 1 1 , 1 , 1 = 1 , - 1 , 2 - 1 4 1 , 1 , 1 = 1 4 3 , - 5 , 7

    2. 1 , - 1 , 4 - 1 , 1 , 3 - - 1 , 1 , 3 · 1 , - 1 , 4 1 , - 1 , 4 · 1 , - 1 , 4 1 , - 1 , 4 = - 1 , 1 , 3 - - 1 + 3 - 4 + 3 1 - 3 + 4 + 4 1 , - 1 , 4 = - 1 , 1 , 3 - 1 6 1 , - 1 , 4 = 1 6 - 7 , 7 , 14 = 7 6 - 1 , 1 , 2

コード(Emacs)

Python 3

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

print('1.')


def spa(x, y):
    return x[0] * y[0] + 2 * x[1] * y[1] + x[2] * y[2]


def spb(x, y):
    return x[0] * y[0] - 3 * x[1] * y[1] + x[0] * y[2] - x[2] * y[1]


sps = [spa, spb]
ts = [(Matrix([[1, 1, 1]]), Matrix([[3, -5, 7]])),
      (Matrix([[1, -1, 4]]), Matrix([[-1, 1, 2]]))]

for i, (sp, (a, b)) in enumerate(zip(sps, ts)):
    print(f'({chr(ord("a") + i)})')
    for t in [a, b, sp(a, b)]:
        pprint(t)
        print()
    print()

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

$ ./sample1.py
1.
(a)
[1  1  1]

[3  -5  7]

0


(b)
[1  -1  4]

[-1  1  2]

0


$

0 コメント:

コメントを投稿