学習環境
- 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(行列の乗法)、練習問題5、6、7、8、9.を取り組んでみる。
コード(Emacs)
Python 3
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from sympy import pprint, Matrix, randMatrix, symbols
import random
import functools
print('5.')
a = Matrix([[1, 2],
[3, -1]])
b = Matrix([[2, 0],
[1, 1]])
pprint(a * b)
pprint(b * a)
print('6.')
c = Matrix([[7, 0],
[0, 7]])
for m in [c * a, a * c, c * b, b * c]:
pprint(m)
n = 10
d = randMatrix(n, n)
a = symbols('a')
i = Matrix([[1 if i == j else 0 for j in range(n)]
for i in range(n)])
c = a * i
print(d * c == c * d == a * d)
print('7.')
x = Matrix([[1, 0, 0]])
a = Matrix([[3, 1, 5],
[2, 0, 1],
[1, 1, 7]])
pprint(x * a)
print('8.')
x = Matrix([[0, 1, 0]])
a = randMatrix(3, 3)
pprint(x * a == a[1, :])
x = Matrix([[0, 0, 1]])
pprint(x * a == a[2, :])
print('9.')
m = random.randrange(1, 10)
n = random.randrange(1, 10)
l = random.randrange(1, 10)
a = randMatrix(m, n)
b = randMatrix(n, l)
c = randMatrix(l, random.randrange(1, 10))
print((a * b * c).transpose() == functools.reduce(lambda x, y: x * y,
map(lambda x: x.transpose(),
[c, b, a])))
入出力結果(Terminal, IPython)
$ ./sample5.py 5. ⎡4 2 ⎤ ⎢ ⎥ ⎣5 -1⎦ ⎡2 4⎤ ⎢ ⎥ ⎣4 1⎦ 6. ⎡7 14⎤ ⎢ ⎥ ⎣21 -7⎦ ⎡7 14⎤ ⎢ ⎥ ⎣21 -7⎦ ⎡14 0⎤ ⎢ ⎥ ⎣7 7⎦ ⎡14 0⎤ ⎢ ⎥ ⎣7 7⎦ True 7. [3 1 5] 8. True True 9. True $
0 コメント:
コメントを投稿