首页 新闻 搜索 专区 学院

一个线性方程组结果为-1.#IND00的问题?

0
悬赏园豆:20 [待解决问题]

#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是什么意思?为什么会出现这样的结果,该如何解决?

毕加猪049的主页 毕加猪049 | 初学一级 | 园豆:180
提问于:2011-07-28 10:11
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册