#include <stdio.h>
#include <math.h>
#define MAX_N 20
#define MAXREPT 100
#define eps 0.00001
int main()
{
int n=8;
int p,q,k;
double err,w=1.5;
static double b[8][8],g[8];
static double x[8],nx[8];
static double a[8][8] =
{
{20,20,1,0,0,0,-1060,-1060},
{352,20,1,0,0,0,-118976,-6760},
{20,318,1,0,0,0,-1060,-16854},
{352,318,1,0,0,0,-122496,-110664},
{0,0,0,20,20,1,-380,-380},
{0,0,0,352,20,1,-6688,-380},
{0,0,0,20,318,1,-6600,-104940},
{0,0,0,352,318,1,-116160,-104940}
};
static double c[8] = {53,338,53,348,19,19,330,330};
for (p=0;p<n;p++)
for (q=0;q<n;q++)
{
b[p][q]=-a[p][q]/a[p][p];
g[p]=c[p]/a[p][p];
}
for (p=0;p<MAXREPT;p++)
{
for (q=0;q<n;q++)
nx[q]=g[q];
for (q=0;q<n;q++)
{
for (k=0;k<q;k++)
nx[q]+=b[q][k]*nx[k];
for (k=q+1;k<n;k++)
nx[q]+=b[q][k]*x[k];
nx[q]=(1-w)*x[q]+w*nx[q];
}
err=0;
for (q=0;q<n;q++)
if (err<fabs(nx[q]-x[q])) err=fabs(nx[q]-x[q]);
for (q=0;q<n;q++)
x[q]=nx[q];
if (err<eps)
{
printf("Solve...x_i=\n");
for (p=0;p<n;p++)printf("%lf\n",x[p]);
return 0;
}
}
printf("After %d repeat,no result...\n",MAXREPT);
return 1;
}
这是用超松弛迭代法求解线性方程组的解的程序,可是结果却全是-1.#IND00,不知道是哪里出了问题,求高手解答!
-1.#IND00是什么意思?为什么会出现这样的结果,该如何解决?