2018年9月2日日曜日

学習環境

線型代数入門(松坂 和夫(著)、岩波書店)の第7章(固有値と固有ベクトル)、2(固有多項式(特性多項式))、問題3.を取り組んでみる。


  1. f A x = det x I n - A = det x I r - A 1 B O x I n - r - A 2 = det x I r - A t · det x I n - r - A 2 = f A 1 x f A 2 x

    B ではなく C の場合も同様。

コード(Emacs)

Python 3

#!/usr/bin/env python3
from sympy import pprint, symbols, Matrix, I, solve
import random

print('3.')

x = symbols('x')


def f(n, A):
    def g(i, j):
        if i == j:
            return 1
        return 0
    In = Matrix([[g(i, j) for j in range(n)]
                 for i in range(n)])
    return (x * In - A)


for _ in range(10):
    n = random.randrange(2, 5)
    r = random.randrange(1, n)
    A1 = Matrix([[symbols(f'a{i + 1}{j + 1}') for j in range(r)]
                 for i in range(r)])
    A2 = Matrix([[symbols(f'c{i + 1}{j + 1}') for j in range(n - r)]
                 for i in range(n - r)])
    B = Matrix([[symbols(f'b{i + 1}{j + 1}') for j in range(n - r)]
                for i in range(r)])

    def h(i, j):
        if i < r and j < r:
            return A1[i, j]
        if i < r and j >= r:
            return B[i, j - r]
        if j < r:
            return 0
        return A2[i - r, j - r]
    A = Matrix([[h(i, j) for j in range(n)]
                for i in range(n)])
    fa = f(n, A)
    fa1 = f(r, A1)
    fa2 = f(n - r, A2)
    for t in [A, fa.det().expand() == (fa1.det() * fa2.det()).expand()]:
        pprint(t)
        print()
    print()
    A1 = Matrix([[symbols(f'a{i + 1}{j + 1}') for j in range(r)]
                 for i in range(r)])
    A2 = Matrix([[symbols(f'c{i + 1}{j + 1}') for j in range(n - r)]
                 for i in range(n - r)])
    B = Matrix([[symbols(f'b{i + 1}{j + 1}') for j in range(r)]
                for i in range(n - r)])

    def h(i, j):
        if i < r and j < r:
            return A1[i, j]
        if i < r and j >= r:
            return 0
        if j < r:
            return B[i - r, j]
        return A2[i - r, j - r]
    A = Matrix([[h(i, j) for j in range(n)]
                for i in range(n)])
    fa = f(n, A)
    fa1 = f(r, A1)
    fa2 = f(n - r, A2)
    for t in [A, fa.det().expand() == (fa1.det() * fa2.det()).expand()]:
        pprint(t)
        print()
    print()

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

$ ./sample3.py
3.
⎡a₁₁  b₁₁  b₁₂⎤
⎢             ⎥
⎢ 0   c₁₁  c₁₂⎥
⎢             ⎥
⎣ 0   c₂₁  c₂₂⎦

True


⎡a₁₁   0    0 ⎤
⎢             ⎥
⎢b₁₁  c₁₁  c₁₂⎥
⎢             ⎥
⎣b₂₁  c₂₁  c₂₂⎦

True


⎡a₁₁  a₁₂  a₁₃  b₁₁⎤
⎢                  ⎥
⎢a₂₁  a₂₂  a₂₃  b₂₁⎥
⎢                  ⎥
⎢a₃₁  a₃₂  a₃₃  b₃₁⎥
⎢                  ⎥
⎣ 0    0    0   c₁₁⎦

True


⎡a₁₁  a₁₂  a₁₃   0 ⎤
⎢                  ⎥
⎢a₂₁  a₂₂  a₂₃   0 ⎥
⎢                  ⎥
⎢a₃₁  a₃₂  a₃₃   0 ⎥
⎢                  ⎥
⎣b₁₁  b₁₂  b₁₃  c₁₁⎦

True


⎡a₁₁  b₁₁⎤
⎢        ⎥
⎣ 0   c₁₁⎦

True


⎡a₁₁   0 ⎤
⎢        ⎥
⎣b₁₁  c₁₁⎦

True


⎡a₁₁  a₁₂  b₁₁⎤
⎢             ⎥
⎢a₂₁  a₂₂  b₂₁⎥
⎢             ⎥
⎣ 0    0   c₁₁⎦

True


⎡a₁₁  a₁₂   0 ⎤
⎢             ⎥
⎢a₂₁  a₂₂   0 ⎥
⎢             ⎥
⎣b₁₁  b₁₂  c₁₁⎦

True


⎡a₁₁  a₁₂  b₁₁  b₁₂⎤
⎢                  ⎥
⎢a₂₁  a₂₂  b₂₁  b₂₂⎥
⎢                  ⎥
⎢ 0    0   c₁₁  c₁₂⎥
⎢                  ⎥
⎣ 0    0   c₂₁  c₂₂⎦

True


⎡a₁₁  a₁₂   0    0 ⎤
⎢                  ⎥
⎢a₂₁  a₂₂   0    0 ⎥
⎢                  ⎥
⎢b₁₁  b₁₂  c₁₁  c₁₂⎥
⎢                  ⎥
⎣b₂₁  b₂₂  c₂₁  c₂₂⎦

True


⎡a₁₁  a₁₂  a₁₃  b₁₁⎤
⎢                  ⎥
⎢a₂₁  a₂₂  a₂₃  b₂₁⎥
⎢                  ⎥
⎢a₃₁  a₃₂  a₃₃  b₃₁⎥
⎢                  ⎥
⎣ 0    0    0   c₁₁⎦

True


⎡a₁₁  a₁₂  a₁₃   0 ⎤
⎢                  ⎥
⎢a₂₁  a₂₂  a₂₃   0 ⎥
⎢                  ⎥
⎢a₃₁  a₃₂  a₃₃   0 ⎥
⎢                  ⎥
⎣b₁₁  b₁₂  b₁₃  c₁₁⎦

True


⎡a₁₁  b₁₁⎤
⎢        ⎥
⎣ 0   c₁₁⎦

True


⎡a₁₁   0 ⎤
⎢        ⎥
⎣b₁₁  c₁₁⎦

True


⎡a₁₁  b₁₁⎤
⎢        ⎥
⎣ 0   c₁₁⎦

True


⎡a₁₁   0 ⎤
⎢        ⎥
⎣b₁₁  c₁₁⎦

True


⎡a₁₁  b₁₁  b₁₂⎤
⎢             ⎥
⎢ 0   c₁₁  c₁₂⎥
⎢             ⎥
⎣ 0   c₂₁  c₂₂⎦

True


⎡a₁₁   0    0 ⎤
⎢             ⎥
⎢b₁₁  c₁₁  c₁₂⎥
⎢             ⎥
⎣b₂₁  c₂₁  c₂₂⎦

True


⎡a₁₁  a₁₂  b₁₁  b₁₂⎤
⎢                  ⎥
⎢a₂₁  a₂₂  b₂₁  b₂₂⎥
⎢                  ⎥
⎢ 0    0   c₁₁  c₁₂⎥
⎢                  ⎥
⎣ 0    0   c₂₁  c₂₂⎦

True


⎡a₁₁  a₁₂   0    0 ⎤
⎢                  ⎥
⎢a₂₁  a₂₂   0    0 ⎥
⎢                  ⎥
⎢b₁₁  b₁₂  c₁₁  c₁₂⎥
⎢                  ⎥
⎣b₂₁  b₂₂  c₂₁  c₂₂⎦

True


$

0 コメント:

コメントを投稿

関連コンテンツ