2017年5月11日木曜日

学習環境

ラング線形代数学(上)(S.ラング (著)、芹沢 正三 (翻訳)、ちくま学芸文庫)の2章(ベクトル空間)、3(基底)、練習問題2、3.を取り組んでみる。


    1. a 1 =1 1+ a 2 =0 a 2 =1 X=AB ( 1,1 )

    2. a 1 + a 2 =2 a 1 + a 2 =1 a 2 = 3 2 a 1 = 1 2 X= 1 2 A+ 3 2 B ( 1 2 , 3 2 )

    3. 2 a 1 a 2 =1 a 1 =1 a 2 =1 X=A+B ( 1,1 )

    4. 2 a 1 a 2 =4 a 1 =3 a 2 =2 X=3A+2B ( 3,2 )

    1. a 1 a 2 + a 3 =1 a 1 + a 2 =0 a 1 a 3 =0 a 2 = a 1 a 3 = a 1 a 1 + a 1 + a 1 =1 a 1 = 1 3 a 2 = 1 3 a 3 = 1 3 ( 1 3 , 1 3 , 1 3 )

    2. a 2 + a 3 =1 a 1 + a 2 =1 a 1 +2 a 3 =1 a 2 +2 a 3 =2 a 3 =1 a 2 =0 a 1 =1 ( 1,0,1 )

    3. a 1 a 2 + a 3 =0 a 1 + a 2 =0 a 1 a 3 =1 a 2 = a 1 a 1 + a 1 + a 1 1=0 a 1 = 1 3 a 2 = 1 3 a 3 = 2 3 ( 1 3 , 1 3 , 2 3 )

コード(Emacs)

Python 3

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from sympy import Symbol, solve

x = Symbol('x')
y = Symbol('y')
z = Symbol('z')

exprs = [((1, 0), (1, 1), (0, 1)),
         ((2, 1), (1, -1), (1, 1)),
         ((1, 1), (2, 1), (-1, 0)),
         ((4, 3), (2, 1), (-1, 0))]

for i, ((x1, x2), (a1, a2), (b1, b2)) in enumerate(exprs):
    print('({0})'.format(chr(ord('a') + i)))
    expr1 = x * a1 + y * b1 - x1
    expr2 = x * a2 + y * b2 - x2
    print(solve((expr1, expr2), dict=True))

exprs = [((1, 0, 0), (1, 1, 1), (-1, 1, 0), (1, 0, -1)),
         ((1, 1, 1), (0, 1, -1), (1, 1, 0), (1, 0, 2)),
         ((0, 0, 1), (1, 1, 1), (-1, 1, 0), (1, 0, -1))]

for i, ((x1, x2, x3),
        (a1, a2, a3), (b1, b2, b3), (c1, c2, c3)) in enumerate(exprs):
    print('({0})'.format(chr(ord('a') + i)))
    expr1 = x * a1 + y * b1 + z * c1 - x1
    expr2 = x * a2 + y * b2 + z * c2 - x2
    expr3 = x * a3 + y * b3 + z * c3 - x3
    print(solve((expr1, expr2, expr3), dict=True))

入出力結果(Terminal, IPython)

$ ./sample2.py
(a)
[{x: 1, y: -1}]
(b)
[{x: 1/2, y: 3/2}]
(c)
[{x: 1, y: 1}]
(d)
[{x: 3, y: 2}]
(a)
[{x: 1/3, y: -1/3, z: 1/3}]
(b)
[{x: 1, y: 0, z: 1}]
(c)
[{x: 1/3, y: -1/3, z: -2/3}]
$

0 コメント:

コメントを投稿