応用手法まとめ(技術・数理モデル・活用分野)
分解手法 | 数式形式 | 数理的意味・特徴 | 代表的応用分野 |
---|---|---|---|
LU分解 | $A = LU$ | 連立一次方程式を下三角・上三角に分解し高速解法を実現 | 構造解析、有限要素法(FEM)、電気回路解析、流体計算 |
QR分解 | $A = QR$ | 直交基底生成、数値安定な最小二乗法、直交変換 | 回帰分析、PCAの前処理、制御工学、信号直交化、3Dグラフィクス |
固有値分解 | $A = PDP^{-1}$ | 固有値・固有ベクトル取得、行列の対角化、振動・波動・拡大縮小・回転成分抽出 | 振動解析、安定性評価、量子力学、モード解析、画像処理、遺伝子解析 |
シュール分解 | $A = QUQ^{-1}$ | 任意行列の上三角化、固有値解析の安定化 | 固有値計算前処理、非対称システム解析、複素行列処理 |
スペクトル分解 | $A = \lambda_1 H_1 + \dots + \lambda_k H_k$ | 固有空間分解、作用を固有値ごとに分離 | モード分解、波動方程式、流体力学、振動工学、信号分離 |
特異値分解 (SVD) | $A = U \Sigma V^{\mathrm{T}}$ | 非正方行列対応、次元削減、ノイズ除去、情報圧縮、最小二乗最適化 | 画像・音声圧縮、レコメンドエンジン、PCA、機械学習前処理、医用画像処理 |
# -*- coding: utf-8 -*-
# 各種行列分解のデモプログラム / Demonstration of Matrix Decompositions
import numpy as np
from scipy.linalg import lu, qr, eig, schur, svd
# ランダムな正方行列Aを作成 / Create a random square matrix A
np.random.seed(0)
A = np.random.rand(3, 3)
# 1. LU分解 / LU Decomposition
P, L, U = lu(A)
print("=== LU Decomposition ===")
print("L:\n", L)
print("U:\n", U)
# 2. QR分解 / QR Decomposition
Q, R = qr(A)
print("\n=== QR Decomposition ===")
print("Q:\n", Q)
print("R:\n", R)
# 3. 固有値分解 / Eigenvalue Decomposition
eigvals, eigvecs = eig(A)
D = np.diag(eigvals)
P = eigvecs
P_inv = np.linalg.inv(P)
print("\n=== Eigenvalue Decomposition ===")
print("P (Eigenvectors):\n", P)
print("D (Eigenvalues on diagonal):\n", D)
# 4. シュール分解 / Schur Decomposition
Q_schur, U_schur = schur(A)
print("\n=== Schur Decomposition ===")
print("Q:\n", Q_schur)
print("U (Upper triangular):\n", U_schur)
# 5. スペクトル分解(今回は簡略化して固有値と射影を表示) / Spectral Decomposition
print("\n=== Spectral Decomposition ===")
for i, lam in enumerate(eigvals):
H = np.outer(eigvecs[:, i], np.linalg.inv(eigvecs)[i, :])
print(f"λ_{i+1} * H_{i+1}:\n", lam * H)
# 6. 特異値分解 / Singular Value Decomposition (SVD)
U_svd, Sigma_svd, Vt_svd = svd(A)
Sigma_mat = np.zeros_like(A)
np.fill_diagonal(Sigma_mat, Sigma_svd)
print("\n=== Singular Value Decomposition (SVD) ===")
print("U:\n", U_svd)
print("Σ:\n", Sigma_mat)
print("V^T:\n", Vt_svd)
# -*- coding: utf-8 -*-
# 連立一次方程式と固有値問題のPython実演 / Linear Algebra Applications in Python
import numpy as np
from scipy.linalg import solve, eig
import matplotlib.pyplot as plt
# ------------------------------
# 1. 連立一次方程式 Ax = b の解法
# Solve Ax = b (Static/Equilibrium Model)
# ------------------------------
# 行列 A / Matrix A
A = np.array([[3, 2],
[1, 2]])
# 右辺ベクトル b / Vector b
b = np.array([5, 5])
# 解 x を計算 / Solve for x
x = solve(A, b)
print("=== Linear System Solution ===")
print("Solution x:", x)
# ------------------------------
# 2. 固有値問題 Ax = λx の解法
# Solve Eigenvalue Problem (Dynamic/Transient Model)
# ------------------------------
# 固有値と固有ベクトルを計算 / Calculate eigenvalues and eigenvectors
eigenvalues, eigenvectors = eig(A)
print("\n=== Eigenvalue Problem ===")
print("Eigenvalues:", eigenvalues)
print("Eigenvectors:\n", eigenvectors)
# ------------------------------
# 3. 可視化 / Visualization
# ------------------------------
# 解のベクトルをプロット / Plot solution vector
plt.figure()
plt.quiver(0, 0, x[0], x[1], angles='xy', scale_units='xy', scale=1, color='r')
plt.xlim(0, max(x[0], x[1]) + 1)
plt.ylim(0, max(x[0], x[1]) + 1)
plt.title('Solution Vector x')
plt.grid(True)
plt.show()
# 固有ベクトルをプロット / Plot eigenvectors
plt.figure()
for i in range(len(eigenvalues)):
vec = eigenvectors[:, i].real
plt.quiver(0, 0, vec[0], vec[1], angles='xy', scale_units='xy', scale=1, label=f'λ={eigenvalues[i].real:.2f}')
plt.xlim(-2, 2)
plt.ylim(-2, 2)
plt.title('Eigenvectors')
plt.grid(True)
plt.legend()
plt.show()