Java 如何从高斯问题中实现 argmax
How to implement argmax from gaussian problem in Java
我正在研究高斯消元(准确地说,我正在尝试将矩阵转换为行阶梯形式)
并立即研究一些可能对我有帮助的资源。我在维基百科中找到了一个与高斯消去函数相关的伪代码。
h := 1 /* Initialization of the pivot row */
k := 1 /* Initialization of the pivot column */
while h ≤ m and k ≤ n
/* Find the k-th pivot: */
i_max := argmax (i = h ... m, abs(A[i, k]))
if A[i_max, k] = 0
/* No pivot in this column, pass to next column */
k := k+1
else
swap rows(h, i_max)
/* Do for all rows below pivot: */
for i = h + 1 ... m:
f := A[i, k] / A[h, k]
/* Fill with zeros the lower part of pivot column: */
A[i, k] := 0
/* Do for all remaining elements in current row: */
for j = k + 1 ... n:
A[i, j] := A[i, j] - A[h, j] * f
/* Increase pivot row and column */
h := h + 1
k := k + 1
我不确定如何实现伪代码第 6 行所述的 argmax
功能。
我将表达式 argmax(i = h ... m, abs(A[i, k]))
解释为
"find the index i which maximizes the expression abs(A[i,k])
over the range h..m".
换句话说。在 i 上循环(从 h .. m)并找到 abs(A[i,k]) 的最大值,其中 k 是一个常数值(来自包含循环)和 return 索引'i'.
// inline implementation of `argmax_abs_a_ik` inside while loop
int i_max = h;
for (int i = h; i <= m; i++) {
if (Math.abs(A[i,k]) > Math.abs(A[i_max,k])) {
i_max = i;
}
}
// i_max contains result
我正在研究高斯消元(准确地说,我正在尝试将矩阵转换为行阶梯形式) 并立即研究一些可能对我有帮助的资源。我在维基百科中找到了一个与高斯消去函数相关的伪代码。
h := 1 /* Initialization of the pivot row */
k := 1 /* Initialization of the pivot column */
while h ≤ m and k ≤ n
/* Find the k-th pivot: */
i_max := argmax (i = h ... m, abs(A[i, k]))
if A[i_max, k] = 0
/* No pivot in this column, pass to next column */
k := k+1
else
swap rows(h, i_max)
/* Do for all rows below pivot: */
for i = h + 1 ... m:
f := A[i, k] / A[h, k]
/* Fill with zeros the lower part of pivot column: */
A[i, k] := 0
/* Do for all remaining elements in current row: */
for j = k + 1 ... n:
A[i, j] := A[i, j] - A[h, j] * f
/* Increase pivot row and column */
h := h + 1
k := k + 1
我不确定如何实现伪代码第 6 行所述的 argmax
功能。
我将表达式 argmax(i = h ... m, abs(A[i, k]))
解释为
"find the index i which maximizes the expression
abs(A[i,k])
over the range h..m".
换句话说。在 i 上循环(从 h .. m)并找到 abs(A[i,k]) 的最大值,其中 k 是一个常数值(来自包含循环)和 return 索引'i'.
// inline implementation of `argmax_abs_a_ik` inside while loop
int i_max = h;
for (int i = h; i <= m; i++) {
if (Math.abs(A[i,k]) > Math.abs(A[i_max,k])) {
i_max = i;
}
}
// i_max contains result