📄 d1r1f.java
字号:
public class d1r1F
{
void gaussj(double a[], int n, double b[])
{
int i, j, k, l, ll, irow, icol;
icol = 0;
irow = 0;
double big, pivinv, dum;
int ipiv[] = new int[50];
int indxr[] = new int[50];
int indxc[] = new int[50];
for (j = 0; j <= n - 1; j++)
{
ipiv[j] = 0;
}
for (i = 0; i <= n - 1; i++)
{
big = 0.0;
for (j = 0; j <= n - 1; j++)
{
if (ipiv[j] != 1)
{
for (k = 0; k <= n - 1; k++)
{
if (ipiv[k] == 0)
{
if (Math.abs(a[j * n + k]) >= big)
{
big = Math.abs(a[j * n + k]);
irow = j;
icol = k;
}
else if (ipiv[k] > 1)
{
System.out.println("singular matrix");
}
}
}
}
}
ipiv[icol] = ipiv[icol] + 1;
if (irow != icol)
{
for (l = 0; l <= n - 1; l++)
{
dum = (a[irow * n + l]);
a[irow * n + l] = a[icol * n + l];
a[icol * n + l] = dum;
}
dum = b[irow];
b[irow] = b[icol];
b[icol] = dum;
}
indxr[i] = irow;
indxc[i] = icol;
if (a[icol * n + icol] == 0.0)
{
System.out.println( "singular matrix.");
System.exit(1);
}
pivinv = 1.0 / (a[icol * n + icol]);
a[icol * n + icol] = 1.0;
for (l = 0; l <= n - 1; l++)
{
a[icol * n + l] = a[icol * n + l] * pivinv;
}
b[icol]=b[icol] * pivinv;
for (ll = 0; ll <= n - 1; ll++)
{
if (ll != icol)
{
dum = a[ll * n + icol];
a[ll * n + icol] = 0.0;
for (l = 0; l <= n - 1; l++)
{
a[ll * n + l] = a[ll * n + l] - a[icol * n + l] * dum;
}
b[ll] = b[ll] - b[icol] * dum;
}
}
for (l = n - 1; l <= 0; l--)
{
if (indxr[l] != indxc[l])
{
for (k = 0; k <= n - 1; k++)
{
dum = a[k * n + indxr[l]];
a[k * n + indxr[l]] = a[k * n + indxc[l]];
a[k * n + indxr[l]] = dum;
}
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -