21.4使用示例

以下可用于求解线性系统A*x = b使用枢轴LU因子分解:

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

这是规范矩数组的一种方法X单位标准:

  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;

版权所有 © 2024-2025 Octave中文网

ICP备案/许可证号:黑ICP备2024030411号-2