2017年6月4日日曜日

学習環境

ラング線形代数学(上)(S.ラング (著)、芹沢 正三 (翻訳)、ちくま学芸文庫)の3章(行列)、3(行列の乗法)、練習問題10.を取り組んでみる。


  1. SP1 〈 A,B 〉= ∑ i=1 n ( ∑ j=1 n a j m ji ) b i = ∑ i=1 n ( ∑ j=1 n a j b i m ji ) 〈 B,A 〉= ∑ i=1 n ( ∑ j=1 n b j m ji ) a i = ∑ i=1 n ( ∑ j=1 n a i b j m ji ) = ∑ i=1 n ( ∑ j=1 n a i b j m ij ) 〈 A,B 〉=〈 B,A 〉 SP2 〈 A,( B+C ) 〉= ∑ i=1 n ( ∑ j=1 n a j m ji )( b i + c i ) = ∑ i=1 n ( ∑ j=1 n a j b i m ji )+ ∑ i=1 n ( ∑ j=1 n a j c i m ji ) =〈 A,B 〉+〈 A,C 〉 〈 ( B+C ),A 〉=〈 A,( B+C ) 〉 SP3 〈 xA,B 〉= ∑ i=1 n ( ∑ j=1 n x a j m ji ) b i =x ∑ i=1 n ( ∑ j=1 n a j m ji ) b i =x〈 A,B 〉 〈 A,xB 〉= ∑ i=1 n ( ∑ j=1 n x a j m ji )x b i =x ∑ i=1 n ( ∑ j=1 n x a j m ji ) b i =x〈 A,B 〉 A=( 1 0 ) M=( −1 0 0 0 ) B=( 1 0 ) A t MB=( −1 0 )( 1 0 )=( −1 )

コード(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 コメント:

コメントを投稿