1.4 Examples of Usag

Last-modified: 2025-03-06 (木) 20:45:36

21.4 使用例

A*x = b ピボット LU 分解を使用して 線形システムを解くには、次の式を使用できます。

 [L, U, P] = lu (A); ## now L*U = P*A
 x = U \ (L \ P) * b;

これは、行列Xの列を単位ノルムに正規化する 1 つの方法です。

 s = norm (X, "columns");
 X /= diag (s);

同じことはブロードキャストでも実現できます (ブロードキャストを参照)。

 s = norm (X, "columns");
 X ./= s;

次の式は、順列ベクトルpによって与えられた順列の符号を効率的に計算する方法です。これは、Octave の以前のバージョンでも動作しますが、速度は遅くなります。

 det (eye (length (p))(p, :))

A*x = b 最後に、 SVD (スケルトンのみ) を使用して、Tikhonov 正則化 (リッジ回帰) による 線形システムを解く方法を次に示します。

 m = rows (A); n = columns (A);
 [U, S, V] = svd (A);
 ## determine the regularization factor alpha
 ## alpha = ...
 ## transform to orthogonal basis
 b = U'*b;
 ## Use the standard formula, replacing A with S.
 ## S is diagonal, so the following will be very fast and accurate.
 x = (S'*S + alpha^2 * eye (n)) \ (S' * b);
 ## transform to solution basis
 x = V*x;