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 (только каркас):
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;
© 1996–2023 The Octave Project Developers
Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies.
Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one.Permission is granted to copy and distribute translations of this manual into another language, under the above conditions for modified versions.
https://docs.octave.org/v9.2.0/Example-Code.html