学習環境
- Surface 3 (4G LTE)、Surface 3 タイプ カバー、Surface ペン(端末)
- Windows 10 Pro (OS)
- 数式入力ソフト(TeX, MathML): MathType
- MathML対応ブラウザ: Firefox、Safari
- MathML非対応ブラウザ(Internet Explorer, Google Chrome...)用JavaScript Library: MathJax
- 参考書籍
ラング線形代数学(上)(S.ラング (著)、芹沢 正三 (翻訳)、ちくま学芸文庫)の3章(行列)、3(行列の乗法)、練習問題10.を取り組んでみる。
コード(Emacs)
Python 3
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from sympy import pprint, Matrix, randMatrix, symbols
import random
for i in range(1, 6):
print(i)
i1 = random.randrange(100)
i2 = random.randrange(100)
i3 = random.randrange(100)
a = random.randrange(100)
b = random.randrange(100)
c = random.randrange(100)
m = Matrix([[i1, a, b],
[a, i2, c],
[b, c, i3]])
print(m.transpose() == m)
def mul(a, b):
return a.transpose() * m * b
for j in range(1, 6):
print('{0}-{1}'.format(i, j))
a = randMatrix(3, 1)
b = randMatrix(3, 1)
c = randMatrix(3, 1)
x = random.randrange(100)
print(mul(a, b) == mul(b, a))
print(mul(a, b + c) == (mul(a, b) + mul(a, c)) == mul(b + c, a))
print(mul(x * a, b) == mul(a, x * b) == x * mul(a, b))
a = Matrix([[1],
[0]])
m = Matrix([[-1, 0],
[0, 0]])
b = Matrix([[1],
[0]])
print('< 0')
print(m.transpose() == m)
pprint(a.transpose() * m * b)
入出力結果(Terminal, IPython)
$ ./sample10.py 1 True 1-1 True True True 1-2 True True True 1-3 True True True 1-4 True True True 1-5 True True True 2 True 2-1 True True True 2-2 True True True 2-3 True True True 2-4 True True True 2-5 True True True 3 True 3-1 True True True 3-2 True True True 3-3 True True True 3-4 True True True 3-5 True True True 4 True 4-1 True True True 4-2 True True True 4-3 True True True 4-4 True True True 4-5 True True True 5 True 5-1 True True True 5-2 True True True 5-3 True True True 5-4 True True True 5-5 True True True < 0 True [-1] $
0 コメント:
コメントを投稿