• 大小: 6KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-10
  • 语言: C/C++
  • 标签: 潮流  C++  

资源简介

使用C++编写高斯赛德尔法的潮流计算程序,将实虚部用一个复数类处理

资源截图

代码片段和文件信息


#include 
#include 
using namespace std;
class complex
{
public:
complex(float r=0float i=0){real=r;imag=i;}
void set(float rfloat i){real=r;imag=i;}
void setimag(float i){imag=i;}
float getimag(){return imag;}
void show(){cout< float absc(){return sqrt(real*real+imag*imag);}
float rad(){return atan(imag/real);}
float ai(){return atan(imag/real)*180/3.14159;}
int jud(){if(real!=0||imag!=0)return 1;else return 0;}
complex conj(){return complex(real-imag);}
    complex operator + (complex c2){return complex(real+c2.realimag+c2.imag);}
    complex operator - (complex c2){return complex(real-c2.realimag-c2.imag);}
complex operator * (complex c2){return complex(real*c2.real-imag*c2.imagimag*c2.real+real*c2.imag);}
complex operator / (complex c2){return complex((real*c2.real+imag*c2.imag)/(c2.real*c2.real+c2.imag*c2.imag)(imag*c2.real-real*c2.imag)/(c2.real*c2.real+c2.imag*c2.imag));}
    ~complex() {}
private:
float real;
float imag;
};

main()
{
  int ijkn=5pv=4maxIter=500;
  static float ybr[5][5]={{0}{01.3787-0.6240-0.75740}{0-0.6241.4539-0.82990}{0-0.7547-0.82991.58460}{0}}; 
  static float ybi[5][5]={{-33.33330031.74600}{0-6.29173.90022.64150}{03.9002-66.98083.112063.4921}{31.74602.64153.1120-35.73790}{0063.49210-66.6667}};
  static float y0r[5][5]={0};
  static float y0i[5][5]={{000-1.587300}{000.2500}{00.2500.253.0234}{1.511700.2500}{00-3.174600}};  
  float epsdd1theta;
  static float u4=1.05;   
 
  complex u[5]={complex(1.050)complex(10)complex(10)complex(10)complex(u40)};
  complex s[5]={complex(00)complex(-1.6-0.8)complex(-2-1)complex(-3.7-1.3)complex(50)}; 
  complex const c0(00);
  complex c1c2c3;
  complex yb[5][5]y0[5][5]sl[5][5]delta_s[5][5];
  for(i=0;i  {   
  for(j=0;j   {
  yb[i][j].set(ybr[i][j]ybi[i][j]);  
  y0[i][j].set(y0r[i][j]y0i[i][j]);
 
  }  
  }

  eps=0.0001;
  k=0;
 
do{
  d=0;    
  k++;
  for(i=1;i  {     
  if(i==pv)
  {
 c2=c0;
  for(j=0;j   {
  c2=yb[i][j]*u[j]+c2;
  }
      c3=u[i]*c2.conj();
  s[i].setimag(c3.getimag());

  }

     c1=s[i]/u[i];   
     c3=c0;
    
     for(j=0;j      if(j != i)
  {  
 c3=yb[i][j]*u[j]+c3;
       }
  c2=c1.conj()-c3;
  c1=c2/yb[i][i];  
  c3=c1-u[i];
  
  d1=c3.absc();     
      if(d  d=d1;   

   if(i==pv)
   {
   theta=c1.rad();
   u[i].set(u4*cos(theta)u4*sin(theta));
   }
   else
      u[i]=c1;     

  }
 
} while(d > eps && k < maxIter);

  cout<<‘k‘<<‘=‘<  for(i=0;i  {
     cout<<‘u‘<  cout<      
 if(i==pv)
     {
  cout<<‘S‘<       s[i].show();
  cout<      }
    
  }    

  c2=c0;
  for(j=0;j  {
 c2=y

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       6416  2013-01-08 21:15  ld class.plg

     文件       3638  2013-01-08 21:15  ld class.cpp

     文件       3427  2013-01-08 21:03  ld class.dsp

     文件        524  2013-01-08 21:15  ld class.dsw

     文件      41984  2013-01-08 21:15  ld class.ncb

     文件      48640  2013-01-08 21:15  ld class.opt

----------- ---------  ---------- -----  ----

               104629                    6


评论

共有 条评论