2017年10月23日月曜日

学習環境

ラング線形代数学(上)(S.ラング (著)、芹沢 正三 (翻訳)、ちくま学芸文庫)の1章(R^n におけるベクトル)、6(複素数)、練習問題6.を取り組んでみる。


    1. A,B= k=1 n α k β k ¯ B,A ¯ = k=1 n β k α k ¯ ¯ = k=1 n β k ¯ α k = k=1 n α k β k ¯ A,B= B,A ¯

    2. A, B+C = k=1 n α k β k + γ k ¯ = k=1 n α k ( β k ¯ + γ k ¯ ) = k=1 n ( α k β k ¯ + α k γ k ¯ ) = k=1 n α k β k ¯ + k=1 n α k γ k ¯ =A,B+A,C

    3. αA ,B = k=1 n α α k β k ¯ =α k=1 n α k β k ¯ =αA,B A,αB = k=1 n α k α β k ¯ = k=1 n α k α ¯ β k ¯ = α ¯ k=1 n α k β k ¯ = α ¯ A,B

    4. A=O A,A = k=1 n α k α k ¯ = k=1 n 0 0 ¯ =0 AO A,A = k=1 n α k α k ¯ = k=1 n | α k | 2 >0

コード(Emacs)

Python 3

#!/usr/bin/env python3
from sympy import pprint, symbols, I
import functools
print('6.')
a1, b1, a2, b2, a3, b3, a4, b4, a5, b5, a6, b6 = symbols(
    'a1, b1, a2, b2, a3, b3, a4, b4 a5 b5 a6 b6', real=True)
A = [a1 + b1 * I, a2 + b2 * I]
B = [a3 + b3 * I, a4 + b4 * I]
C = [a5 + b5 * I, a6 + b6 * I]
a = symbols('a')


def dot(A, B):
    return functools.reduce(
        lambda x, y: x + y,
        [a * b.conjugate() for a, b in zip(A, B)]
    )


def add(A, B):
    return [x + y for x, y in zip(A, B)]


def scalarMul(a, A):
    return [a * x for x in A]

for t in [A, B, C]:
    pprint(t)
    print()

for i, (l, r) in enumerate(
        [(dot(A, B), dot(B, A).conjugate()),
         (dot(A, add(B, C)), dot(A, B) + dot(A, C)),
         (dot(scalarMul(a, A), B), a * dot(A, B)),
         (dot(A, scalarMul(a, B)), a.conjugate() * dot(A, B))], 1):
    print(f'({i})')
    for t in [l, r, l.expand() == r.expand()]:
        pprint(t)
        print()
    print()

A = [0, 0]
print(dot(A, A))

A = [I, 0]
print(dot(A, A))

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

$ ./sample6.py
6.
[a₁ + ⅈ⋅b₁, a₂ + ⅈ⋅b₂]

[a₃ + ⅈ⋅b₃, a₄ + ⅈ⋅b₄]

[a₅ + ⅈ⋅b₅, a₆ + ⅈ⋅b₆]

(1)
(a₁ + ⅈ⋅b₁)⋅(a₃ - ⅈ⋅b₃) + (a₂ + ⅈ⋅b₂)⋅(a₄ - ⅈ⋅b₄)

(a₁ + ⅈ⋅b₁)⋅(a₃ - ⅈ⋅b₃) + (a₂ + ⅈ⋅b₂)⋅(a₄ - ⅈ⋅b₄)

True


(2)
(a₁ + ⅈ⋅b₁)⋅(a₃ + a₅ - ⅈ⋅b₃ - ⅈ⋅b₅) + (a₂ + ⅈ⋅b₂)⋅(a₄ + a₆ - ⅈ⋅b₄ - ⅈ⋅b₆)

(a₁ + ⅈ⋅b₁)⋅(a₃ - ⅈ⋅b₃) + (a₁ + ⅈ⋅b₁)⋅(a₅ - ⅈ⋅b₅) + (a₂ + ⅈ⋅b₂)⋅(a₄ - ⅈ⋅b₄) + 
(a₂ + ⅈ⋅b₂)⋅(a₆ - ⅈ⋅b₆)

True


(3)
a⋅(a₁ + ⅈ⋅b₁)⋅(a₃ - ⅈ⋅b₃) + a⋅(a₂ + ⅈ⋅b₂)⋅(a₄ - ⅈ⋅b₄)

a⋅((a₁ + ⅈ⋅b₁)⋅(a₃ - ⅈ⋅b₃) + (a₂ + ⅈ⋅b₂)⋅(a₄ - ⅈ⋅b₄))

True


(4)
                        _                           _
(a₁ + ⅈ⋅b₁)⋅(a₃ - ⅈ⋅b₃)⋅a + (a₂ + ⅈ⋅b₂)⋅(a₄ - ⅈ⋅b₄)⋅a

                                                    _
((a₁ + ⅈ⋅b₁)⋅(a₃ - ⅈ⋅b₃) + (a₂ + ⅈ⋅b₂)⋅(a₄ - ⅈ⋅b₄))⋅a

True


0
1
$

0 コメント:

コメントを投稿