| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 733 人关注过本帖
标题:复数矩阵求逆矩阵,提示为奇异阵,实际是非奇异阵,为什么?望高手指点,谢 ...
取消只看楼主 加入收藏
dongkunjang
Rank: 1
来 自:北京
等 级:新手上路
帖 子:4
专家分:0
注 册:2010-3-4
结帖率:0
收藏
已结贴  问题点数:20 回复次数:0 
复数矩阵求逆矩阵,提示为奇异阵,实际是非奇异阵,为什么?望高手指点,谢谢!
#include <iostream.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
void rinv(double   ar[][3],double  ai[][3],int n);
void main()
{
    double arr[3][3]={{3,-1,-1},{-1,1,0},{-1,0,1}};
    double aii[3][3]={{0,0,0},{0,0,0},{0,0,0}};
       arr[0][0]=(0.3*5/9);//V/V接线阻抗阵
       aii[0][0]=(0.3*5/9);
       arr[0][1]=(-0.3/9);
       aii[0][1]=(-0.3/9);
       arr[0][2]=(-0.3*4/9);
       aii[0][2]=(-0.3*4/9);

       arr[1][0]=(-0.3/9);
       aii[1][0]=(-0.3/9);
       arr[1][1]=(0.3*2/9);
       aii[1][1]=(0.3*2/9);
       arr[1][2]=(-0.3/9);
       aii[1][2]=(-0.3/9);

       arr[2][0]=(-0.3*4/9);
       aii[2][0]=(-0.3*4/9);
       arr[2][1]=(-0.3/9);
       aii[2][1]=(-0.3/9);
       arr[2][2]=(0.3*5/9);
       aii[2][2]=(0.3*5/9);

       /*arr[0][0]=0.167;//V/V接线阻抗阵
       aii[0][0]=0.167;
       arr[0][1]=-0.033;
       aii[0][1]=-0.033;
       arr[0][2]=-0.133;
       aii[0][2]=-0.133;

       arr[1][0]=-0.033;
       aii[1][0]=-0.033;
       arr[1][1]=0.067;
       aii[1][1]=0.067;
       arr[1][2]=-0.033;
       aii[1][2]=-0.033;

       arr[2][0]=-0.133;
       aii[2][0]=-0.133;
       arr[2][1]=-0.033;
       aii[2][1]=-0.033;
       arr[2][2]=0.167;
       aii[2][2]=0.167;*/
      
    rinv( arr,aii,3);
    for( int i=0;i<3;i++)
      { for(int j=0;j<3;j++)
              cout<<arr[i][j]<<" ";
          cout<<endl;
      }
      cout<<endl;
      for( i=0;i<3;i++)
      { for(int j=0;j<3;j++)
              cout<<aii[i][j]<<" ";
          cout<<endl;
      }
      cout<<endl;
   
}
 void rinv(double ar[][3],double ai[][3],int n)//求矩阵a:n*n的逆阵
  {
      int i,j,k;
      int *is,*js;
      double p,q,s,t,d,b;
      is=new int[n];
      js=new int[n];
      for(k=0;k<=n-1;k++)
      {
          d=0.0;
          for(i=k;i<=n-1;i++)
              for(j=k;j<=n-1;j++)
              {
                 p=ar[i][j]*ar[i][j]+ai[i][j]*ai[i][j];
                 if(p>d){d=p;is[k]=i;js[k]=j;}

              }
              if(d+1.0==1.0)
              {
                  delete[] is,js;
                  cout<<"\nA矩阵为奇异阵!没有逆矩阵."<<endl;
                  exit(1);
              }
              if(is[k]!=k)
                  for(j=0;j<=n-1;j++)
                  {
                      t=ar[k][j];ar[k][j]=ar[is[k]][j];ar[is[k]][j]=t;
                      t=ai[k][j];ai[k][j]=ai[is[k]][j];ai[is[k]][j]=t;
                  }
              if(js[k]!=k)
                  for(i=0;i<=n-1;i++)
                  {
                      t=ar[i][k];ar[i][k]=ar[i][js[k]];ar[i][js[k]]=t;
                      t=ai[i][k];ai[i][k]=ai[i][js[k]];ai[i][js[k]]=t;
                  }
              ar[k][k]=ar[k][k]/d;ai[k][k]=-ai[k][k]/d;
              for(j=0;j<=n-1;j++)
                  if(j!=k)
                  {
                      p=ar[k][j]*ar[k][k];q=ai[k][j]*ai[k][k];
                      s=(ar[k][j]+ai[k][j])*(ar[k][k]+ai[k][k]);
                      ar[k][j]=p-q;ai[k][j]=s-p-q;
                  }
              for(i=0;i<=n-1;i++)
                  if(i!=k)
                  {
                     for(j=0;j<=n-1;j++)
                         if(j!=k)
                         {
                             p=ar[k][j]*ar[i][k];q=ai[k][j]*ai[i][k];
                             s=(ar[k][j]+ai[k][j])*(ar[i][k]+ai[i][k]);
                             t=p-q;b=s-p-q;
                             ar[i][j]=ar[i][j]-t;
                             ai[i][j]=ai[i][j]-b;
                         }
                  }
              for(i=0;i<=n-1;i++)
                 if(i!=k)
                 {
                     p=ar[i][k]*ar[k][k];q=ai[i][k]*ai[k][k];
                     s=(ar[i][k]+ai[i][k])*(ar[k][k]+ai[k][k]);
                     ar[i][k]=q-p;ai[i][k]=p+q-s;
                 }
      }
      for(k=n-1;k>=0;k--)
      {
          if(js[k]!=k)
              for(j=0;j<=n-1;j++)
              {
                  t=ar[k][j];ar[k][j]=ar[js[k]][j];ar[js[k]][j]=t;
                  t=ai[k][j];ai[k][j]=ai[js[k]][j];ai[js[k]][j]=t;
              }
          if(is[k]!=k)
              for(i=0;i<=n-1;i++)
              {
                  t=ar[i][k];ar[i][k]=ar[i][is[k]];ar[i][is[k]]=t;
                  t=ai[i][k];ai[i][k]=ai[i][is[k]];ai[i][is[k]]=t;
              }
      }
      

      delete is,js;

  }
搜索更多相关主题的帖子: 提示 矩阵 复数 
2010-03-30 19:47
快速回复:复数矩阵求逆矩阵,提示为奇异阵,实际是非奇异阵,为什么?望高手指点 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.066366 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved