|
SUBJECT : URGENT
help me to solve multiply matrix with angle 30 degree and -30 degree at positive and negative sequence based on transformer connection
A = | yt -yt*angle -30degree |
| -yt*angle 30degree yt |
B = | yt -yt*angle 30 degree |
|-yt * angle -30degree yt |
SEQUENCE COMPONENTS
Transformer Connection Equivalent Sequence Circuit / Admittance Matrix
Positive Negative
Y – G ∆ A B
Y ∆ A B
∆ Y – G B A
∆ Y B A
1) ASSIGNMENT: IMPROVING FAULT ANALYSIS BY USING SEQUENCE COMPONENTS.
CONDITION THAT SHOULD TO REFER FOR GETTING ADMITTANCE OF POSITIVE AND NEGATIVE SEQUENCE [ Y-MATRIX ]
2) COMPILER : VISUAL C++
3) DUE DATE : friday(5 OCT 2007 )
TIME ZONE: (GMT+8.00) KUALA LUMPUR, SINGAPORE
4) STUDY FIELD : ELECTRICAL ENGINEERING MAJORING POWER
BOOK REFER : HADI SAADAT, “POWER SYSTEM ANALYSIS” 2ND EDITION, MC GRAW HILL.
PROGRAMMING
/* MOHD FUAD BIN HAJI ABDUL LATIP
ASSIGNMENT FOR POWER SYSTEM ANALYSIS - PENYELESAIAN SISTEM TIDAK SEIMBANG
KEE97062
*/
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#include <math.h>
//******************************************************************************************
void invmatrik(float **c,int m)
{
int i,j,k,l;
for(i=1;i<=m;i++)
{
c[i][i]=(float)(1.0/c[i][i]);
for(j=1;j<=m;j++)
{
if(j!=i)
{
c[j][i]=c[j][i]*c[i][i];
for(k=1;k<=m;k++)
{
if(k!=i)
{
c[j][k]=c[j][k]-c[j][i]*c[i][k];
if(j==m)
{
c[i][k]=-c[i][i]*c[i][k];
}
}
}
}
}
}
k=m-1;
for(l=1;l<=k;l++){
c[m][l]=-c[m][m]*c[m][l];
}
}
//*****************************************************************************************
void kalimatrik(float **a,float **b,float **c,int tb)
{
int i,j,k,m=1;
float *sem;
sem=(float *)calloc((tb+1)*(tb+1),sizeof(float));
for(i=1;i<=tb*tb;i++)
sem[i]=0;
for(i=1;i<=tb;i++)
{
for(j=1;j<=tb;j++)
{
for(k=1;k<=tb;k++)
{
sem[m] +=a[i][k]*b[k][j];
}
m++;
}
}
m=1;
for(i=1;i<=tb;i++)
for(j=1;j<=tb;j++)
{
c[i][j]=sem[m];
m++;
}
i=0;
free(sem);
}
//********************************************************************************************
void addmatrik(float **A,float **B,float **net,int line)
{
int i,j;
for(i=1;i<=line;i++)
{
for(j=1;j<=line;j++)
{
net[i][j]=A[i][j] + B[i][j];
}
}
}
//********************************************************************************************
float realpart(float R,float X)
{
float Greal;
Greal = R/(R*R + X*X);
return (Greal);
}
float imgpart(float R,float X)
{
float Bimg = -X/(R*R + X*X);
return (Bimg);
}
//--------------------------------------------------------------------------------------------
struct data
{
int send,recv,trans_ada,jen_trans;
float R,X,S,Gzero,Bzero,zf;
};
struct generator
{
int bus,bumi;
float Xgen;
};
struct addbus
{
int nobus;
float G_tambah,B_tambah;
};
struct positif
{
int hantar,terima;
float Rpos,Xpos,Spos,Gpos,Bpos;
};
struct genpos
{
int buspos,bumipos;
float Xgenpos;
};
//*****************************************************************************************
#define saiz 1
#define max_char 10
#define INF 10000000000
int main(void)
{
FILE *fin,*fout,*input;
int jum_data,jum_gen,tambahnilai,i,j,k,jum_bus,pos_data,pos_bus,gen_pos,n,g;
float *realdiag, *imgdiag, **realmatrik, **imgmatrik, **netkaliG, **netkaliB,
**invG, **invB, **netadd,zn,*gpospe, *bpospe, **gposmatrik, **bposmatrik,
**jumkalig, **jumkalib, **jumadd, **gposinv, **bposinv,*Ifg,*IfgN,*IfbN,*Ifb,*Ifg0,
*Ifg2,*Ifb0,*Ifb2,**voltangagalG0,**voltangagalB0,**voltangagalG1a,**voltangagalB1a,
**voltangagalG1b,**voltangagalB1b,*A,*B,*C,*D,*E,*F,**voltfasaG0,**voltfasaB0,**voltfasaG1,
**voltfasaB1,**voltfasaG2,**voltfasaB2;
char file_name[max_char + saiz],file_namepos[max_char + saiz],yes;
struct data *dot;
struct generator *gen;
struct addbus *tambahnilaibus;
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
printf("\n\n\n");
printf("\t\t\tWELCOME TO UNSYMMETRICAL FAULT PROGRAM\n\n\n");
printf("\t\t\tCopyright (c) Fuad Latip 2000\n\n\n");
printf("\t\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n\n\n");
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
fout = fopen("JAWAPAN.txt","w+");
SEMULA:
{
fputs ("\tPlease enter the name of zero sequence file in format .txt:",stdout);
gets (file_name);
printf("\n\n");
if ((fin=fopen(file_name,"r"))==NULL)
{
printf("\t\a\aSORRY. File %s cannot opened.\n\tPlease try again\n\n\n",file_name);
goto SEMULA;
}
}
SEMULA2:
{
fputs ("\tPlease enter the name of positive sequence file in format .txt:",stdout);
gets (file_namepos);
printf("\n\n");
if ((input=fopen(file_namepos,"r"))==NULL)
{
printf("\n\t\a\aSORRY. File %s cannot opened.\n\tPlease try again\n\n\n",file_namepos);
goto SEMULA2;
}
}
//--------------------------------------------------------------------------------------
fscanf(fin,"%d",&jum_data);
fscanf(fin,"%d",&jum_bus);
dot = (struct data *)calloc(jum_data+1,sizeof(struct data));
for(j=1;j<=jum_data;j++)
{
dot[j].send=0;
dot[j].recv=0;
dot[j].trans_ada=0;
dot[j].jen_trans=0;
dot[j].R=0;
dot[j].X=0;
dot[j].S=0;
}
for(j=1;j<=jum_data;j++)
{
fscanf(fin,"%d %d %d %d %f %f %f",&dot[j].send,&dot[j].recv,&dot[j].trans_ada,&dot[j].jen_trans,&dot[j].R,&dot[j].X,&dot[j].S);
}
for(j=1;j<=jum_data;j++)
{
if(!dot[j].trans_ada==1 || (dot[j].trans_ada ==1 && dot[j].jen_trans ==1))
{
dot[j].Gzero = realpart(dot[j].R,dot[j].X);
dot[j].Bzero = imgpart(dot[j].R,dot[j].X);
}
else
{
dot[j].Gzero = 0;
dot[j].Bzero = 0;
}
}
//--------------------------------------------------------------------------------------
jum_gen =0;
fscanf(fin,"%d",&jum_gen);
gen = (struct generator *) calloc(jum_gen+1,sizeof(struct generator));
for(j=1;j<=jum_gen;j++)
{
fscanf(fin,"%d %d %f",&gen[j].bus,&gen[j].bumi,&gen[j].Xgen);
}
zn=0;
fscanf(fin,"%f",&zn);
fscanf(fin,"%f",&dot[j].zf);
tambahnilai = 0;
for(j=1;j<=jum_data;j++)
{
if(dot[j].trans_ada)
if(dot[j].jen_trans == 3 || dot[j].jen_trans == 4)
tambahnilai ++;
}
tambahnilaibus = (struct addbus *)calloc(tambahnilai+1,sizeof(struct addbus));
//--------------------------------------------------------------------------------------
realdiag = (float *)calloc(jum_bus+1,sizeof(float));
imgdiag = (float *)calloc(jum_bus+1,sizeof(float));
//--------------------------------------------------------------------------------------
i=1;
for(j=1;j<=jum_data;j++)
{
if(dot[j].trans_ada==1)
{
if(dot[j].jen_trans==2)
{
dot[j].Gzero = 0;
dot[j].Bzero = 0;
}
else
if(dot[j].jen_trans==3)//star grounded - delta
{
dot[j].Gzero = 0;
dot[j].Bzero = 0;
tambahnilaibus[i].nobus = dot[j].send;
tambahnilaibus[i].G_tambah = realpart(dot[j].R,dot[j].X);
tambahnilaibus[i].B_tambah = imgpart(dot[j].R,dot[j].X);
i++;
}
else
if(dot[j].jen_trans==4)//delta - star grounded
{
dot[j].Gzero = 0;
dot[j].Bzero = 0;
tambahnilaibus[i].nobus = dot[j].recv;
tambahnilaibus[i].G_tambah = realpart(dot[j].R,dot[j].X);
tambahnilaibus[i].B_tambah = imgpart(dot[j].R,dot[j].X);
i++;
}
}
}
//---------------------------------------------------------------------------------------------
realmatrik=(float **)calloc(jum_bus+1,sizeof(float *));
imgmatrik=(float **)calloc(jum_bus+1,sizeof(float *));
for(i=1;i<=jum_bus;i++)
{
realmatrik[i]=(float *)calloc(jum_bus+1,sizeof(float));
imgmatrik[i]=(float *)calloc(jum_bus+1,sizeof(float));
}
for(j=1;j<=jum_bus;j++)
{
realdiag[j]=0;
imgdiag[j]=0;
}
for(j=1;j<=jum_data;j++)
{
if(!dot[j].trans_ada==1 || (dot[j].trans_ada ==1 && dot[j].jen_trans ==1))
{
realdiag[dot[j].send]=realdiag[dot[j].send] + realpart(dot[j].R,dot[j].X);
imgdiag[dot[j].send]=imgdiag[dot[j].send] + imgpart(dot[j].R,dot[j].X) + dot[j].S/2;
realdiag[dot[j].recv]=realdiag[dot[j].recv] + realpart(dot[j].R,dot[j].X);
imgdiag[dot[j].recv]=imgdiag[dot[j].recv] + imgpart(dot[j].R,dot[j].X) + dot[j].S/2;
}
}
for(j=1;j<=tambahnilai;j++)
{
realdiag[tambahnilaibus[j].nobus] +=tambahnilaibus[j].G_tambah;
imgdiag[tambahnilaibus[j].nobus] +=tambahnilaibus[j].B_tambah;
}
for(j=1;j<=jum_gen;j++)
{
if(gen[j].bumi==1)
imgdiag[gen[j].bus] += imgpart(0,(gen[j].Xgen + 3*zn));
}
//------------------------------------------------------------------------------------------
for(j=1;j<=jum_bus;j++)
{
for(i=1;i<=jum_bus;i++)
{
realmatrik[j][i]=0;
imgmatrik[j][i]=0;
}
}
for(i=1;i<=jum_bus;i++)
{
realmatrik[i][i]=realdiag[i];
imgmatrik[i][i]=imgdiag[i];
}
for(k=1;k<=jum_data;k++)
{
realmatrik[dot[k].send][dot[k].recv]= -dot[k].Gzero;
imgmatrik[dot[k].send][dot[k].recv]= -dot[k].Bzero;
realmatrik[dot[k].recv][dot[k].send]= -dot[k].Gzero;
imgmatrik[dot[k].recv][dot[k].send]= -dot[k].Bzero;
}
//---------------------------------------------------------------------------------------
netkaliG=(float **)calloc(jum_bus+1,sizeof(float *));
netkaliB=(float **)calloc(jum_bus+1,sizeof(float *));
invG=(float **)calloc(jum_bus+1,sizeof(float *));
invB=(float **)calloc(jum_bus+1,sizeof(float *));
netadd=(float **)calloc(jum_bus+1,sizeof(float *));
for(i=1;i<=jum_bus;i++)
{
netkaliG[i]=(float *)calloc(jum_bus+1,sizeof(float));
netkaliB[i]=(float *)calloc(jum_bus+1,sizeof(float));
invG[i]=(float *)calloc(jum_bus+1,sizeof(float));
invB[i]=(float *)calloc(jum_bus+1,sizeof(float));
netadd[i]=(float *)calloc(jum_bus+1,sizeof(float));
}
//---------------------------------------------------------------------------------------
for(i=1;i<=jum_bus;i++)
{
for(j=1;j<=jum_bus;j++)
{
netkaliG[i][j]=0;
netkaliB[i][j]=0;
invG[i][j]=0;
invB[i][j]=0;
netadd[i][j]=0;
}
}
kalimatrik(realmatrik,realmatrik,netkaliG,jum_bus);
kalimatrik(imgmatrik,imgmatrik,netkaliB,jum_bus);
addmatrik(netkaliG,netkaliB,netadd,jum_bus);
invmatrik(netadd,jum_bus);
kalimatrik(realmatrik,netadd,invG,jum_bus);
kalimatrik(imgmatrik,netadd,invB,jum_bus);
for(i=1;i<=jum_bus;i++)
{
for(j=1;j<=jum_bus;j++)
{
invG[i][j] = -(invG[i][j]);
invB[i][j] = -(invB[i][j]);
}
}
//----------------------------------------------------------------------------------------
fprintf(fout,"MATRIX Y FOR ZERO SEQUENCE\n");
for(i=1;i<=jum_bus;i++)
{
for(j=1;j<=jum_bus;j++)
{
fprintf(fout,"%.4f %.4fj\t\t",realmatrik[i][j],imgmatrik[i][j]);
}
fprintf(fout,"\n");
}
fprintf(fout,"\n\n");
fprintf(fout,"INVERSE MATRIX Z FOR ZERO SEQUENCE\n");
for(i=1;i<=jum_bus;i++)
{
for(j=1;j<=jum_bus;j++)
{
fprintf(fout,"%.4f + %.4fj\t",invG[i][j],invB[i][j]);
}
fprintf(fout,"\n");
}
//##################################################################################
// JUJUK POSITIF
//##################################################################################
//----------------------------------------------------------------------------------
struct positif *pos;
struct genpos *gpos;
pos_data=0;
pos_bus=0;
fscanf(input,"%d",&pos_data);
fscanf(input,"%d",&pos_bus);
pos = (struct positif *)calloc(pos_data+1,sizeof(struct positif));
for(j=1;j<=pos_data;j++)
{
pos[j].hantar=0;
pos[j].terima=0;
pos[j].Rpos=0;
pos[j].Xpos=0;
pos[j].Spos=0;
}
for(i=1;i<=pos_data;i++)
{
fscanf(input,"%d %d %f %f %f", &pos[i].hantar,&pos[i].terima,&pos[i].Rpos,&pos[i].Xpos,&pos[i].Spos);
}
//----------------------------------------------------------------------------------------
for(k=1;k<=pos_data;k++)
{
pos[k].Gpos = realpart(pos[k].Rpos,pos[k].Xpos);
pos[k].Bpos = imgpart(pos[k].Rpos,pos[k].Xpos);
}
//----------------------------------------------------------------------------------------
// membina location
gpospe = (float *)calloc(pos_bus+1,sizeof(float));
bpospe = (float *)calloc(pos_bus+1,sizeof(float));
gposmatrik=(float **)calloc(pos_bus+1,sizeof(float *));
bposmatrik=(float **)calloc(pos_bus+1,sizeof(float *));
for(i=0;i<=pos_bus;i++)
{
gposmatrik[i]=(float *)calloc(pos_bus+1,sizeof(float));
bposmatrik[i]=(float *)calloc(pos_bus+1,sizeof(float));
}
//----------------------------------------------------------------------------------------
for(j=1;j<=pos_bus;j++)
{
gpospe[j]=0;
bpospe[j]=0;
}
for(j=1;j<=pos_data;j++)
{
gpospe[pos[j].hantar]=gpospe[pos[j].hantar] + realpart(pos[j].Rpos,pos[j].Xpos);
bpospe[pos[j].hantar]=bpospe[pos[j].hantar] + imgpart(pos[j].Rpos,pos[j].Xpos) + pos[j].Spos/2;
gpospe[pos[j].terima]=gpospe[pos[j].terima] + realpart(pos[j].Rpos,pos[j].Xpos);
bpospe[pos[j].terima]=bpospe[pos[j].terima] + imgpart(pos[j].Rpos,pos[j].Xpos) + pos[j].Spos/2;
}
//---------------------------------------------------------------------------------------
//penambahan nilai jika ada generator
gen_pos =0;
fscanf(input,"%d",&gen_pos);
gpos = (struct genpos *) calloc(gen_pos+1,sizeof(struct genpos));
for(j=1;j<=gen_pos;j++)
{
fscanf(input,"%d %d %f",&gpos[j].buspos,&gpos[j].bumipos,&gpos[j].Xgenpos);
}
for(i=1;i<=gen_pos;i++)
{
if(gpos[i].bumipos)
bpospe[gpos[i].buspos] += imgpart(0,(gpos[i].Xgenpos));
}
//------------------------------------------------------------------------------------
for(j=1;j<=pos_bus;j++)
{
for(i=1;i<=pos_bus;i++)
{
gposmatrik[j][i]=0;
bposmatrik[j][i]=0;
}
}
for(i=1;i<=pos_bus;i++)
{
gposmatrik[i][i]=gpospe[i];
bposmatrik[i][i]=bpospe[i];
}
for(k=1;k<=pos_data;k++)
{
gposmatrik[pos[k].hantar][pos[k].terima]= -pos[k].Gpos;
bposmatrik[pos[k].hantar][pos[k].terima]= -pos[k].Bpos;
gposmatrik[pos[k].terima][pos[k].hantar]= -pos[k].Gpos;
bposmatrik[pos[k].terima][pos[k].hantar]= -pos[k].Bpos;
}
//-------------------------------------------------------------------------------------
// inverse matrik
jumkalig=(float **)calloc(pos_bus+1,sizeof(float *));
jumkalib=(float **)calloc(pos_bus+1,sizeof(float *));
jumadd=(float **)calloc(pos_bus+1,sizeof(float *));
gposinv=(float **)calloc(pos_bus+1,sizeof(float *));
bposinv=(float **)calloc(pos_bus+1,sizeof(float *));
for(i=1;i<=pos_bus;i++)
{
jumkalig[i]=(float *)calloc(pos_bus+1,sizeof(float));
jumkalib[i]=(float *)calloc(pos_bus+1,sizeof(float));
jumadd[i]=(float *)calloc(pos_bus+1,sizeof(float));
gposinv[i]=(float *)calloc(pos_bus+1,sizeof(float));
bposinv[i]=(float *)calloc(pos_bus+1,sizeof(float));
}
for(j=1;j<=pos_bus;j++)
{
for(i=1;i<=pos_bus;i++)
{
jumkalig[j][i]=0;
jumkalib[j][i]=0;
jumadd[j][i]=0;
gposinv[j][i]=0;
bposinv[j][i]=0;
}
}
kalimatrik(gposmatrik,gposmatrik,jumkalig,pos_bus);
kalimatrik(bposmatrik,bposmatrik,jumkalib,pos_bus);
addmatrik(jumkalig,jumkalib,jumadd,pos_bus);
invmatrik(jumadd,pos_bus);
kalimatrik(gposmatrik,jumadd,gposinv,pos_bus);
kalimatrik(bposmatrik,jumadd,bposinv,pos_bus);
for(i=1;i<=pos_bus;i++)
{
for(j=1;j<=pos_bus;j++)
{
gposinv[i][j] = -(gposinv[i][j]);
bposinv[i][j] = -(bposinv[i][j]);
}
}
//--------------------------------------------------------------------------------------
fprintf(fout,"\n\n\n");
fprintf(fout,"MATRIX Y FOR POSITIVE/NEGATIVE SEQUENCE\n");
for(i=1;i<=pos_bus;i++)
{
for(j=1;j<=pos_bus;j++)
{
fprintf(fout,"%.4f %.4fj\t\t",gposmatrik[i][j],bposmatrik[i][j]);
}
fprintf(fout,"\n");
}
fprintf(fout,"\n\n");
fprintf(fout,"INVERSE MATRIX Z FOR POSITIVE/NEGATIVE SEQUENCE\n");
for(i=1;i<=pos_bus;i++)
{
for(j=1;j<=pos_bus;j++)
{
fprintf(fout,"%.4f + %.4fj\t",gposinv[i][j],bposinv[i][j]);
}
fprintf(fout,"\n");
}
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
ULANG:
{
printf("\tPLEASE CHOOSE THE FAULT:\n");
printf("\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
printf("\t1. A PHASE TO GROUND FAULT\n\n");
printf("\t2. TWO PHASE TO GROUND FAULT\n\n");
printf("\t3. PHASE TO PHASE FAULT\n\n");
printf("\t4. 3-PHASE FAULT\n\n\n\n");
printf("\tYOUR CHOICE IS:");
scanf("%d",&n);
printf("\n");
if ((n==1 || n==2 || n==3 || n==4)==NULL)
{
printf("\n\n\n\n\n\n\n\n\n\n\n");
printf("\t\a\aYOU ARE ENTER INVALID NUMBER\n\tPLEASE CHOOSE BETWEEN 1-4 ONLY\n\n");
goto ULANG;
}
printf("\tMY CHOICE :%d\t",n);
printf("\n\n\n");
printf("\tFAULT OCCURED AT BUS NUMBER (BETWEEN BUS 1 UNTIL %d):",jum_bus);
scanf("%d",&g);
printf("\n");
printf("\tFAULT OCCURED AT BUS:%d\t",g);
printf("\n\n\n");
printf("\tALL INFORMATION ARE CORRECT?\n\tIF YES PLEASE TYPE 0 AND 1 IF NO:\t");
scanf("%d",&yes);
printf("\n\n");
}
if (yes==1) goto ULANG;
else if (yes==0)
{
printf("\n\t\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n");
printf("\t\t\a\a\aTHANK YOU FOR CHOOSING MY PROGRAM\n");
printf("\n\t\t YOU ANSWER AUTOMATICALLY SAVE IN FILE jawapan.txt\n");
printf("\n\n");
}
//------------------------------------------------------------------------------------------------------
//location untuk arus gagal dan voltan fasa
Ifg = (float *)calloc(jum_bus,sizeof(float));
IfgN = (float *)calloc(jum_bus,sizeof(float));
Ifb = (float *)calloc(jum_bus,sizeof(float));
IfbN = (float *)calloc(jum_bus,sizeof(float));
for(j=1;j<=jum_bus;j++)
{
Ifg[j]=0;
Ifb[j]=0;
IfgN[j]=0;
IfbN[j]=0;
}
voltangagalG0=(float **)calloc(jum_bus+1,sizeof(float *));
voltangagalG1a=(float **)calloc(jum_bus+1,sizeof(float *));
voltangagalG1b=(float **)calloc(jum_bus,sizeof(float *));
voltangagalB0=(float **)calloc(jum_bus,sizeof(float *));
voltangagalB1a=(float **)calloc(jum_bus,sizeof(float *));
voltangagalB1b=(float **)calloc(jum_bus,sizeof(float *));
for(i=1;i<=jum_bus;i++)
{
voltangagalG0[i]=(float *)calloc(jum_bus,sizeof(float));
voltangagalG1a[i]=(float *)calloc(jum_bus,sizeof(float));
voltangagalG1b[i]=(float *)calloc(jum_bus,sizeof(float));
voltangagalB0[i]=(float *)calloc(jum_bus,sizeof(float));
voltangagalB1a[i]=(float *)calloc(jum_bus,sizeof(float));
voltangagalB1b[i]=(float *)calloc(jum_bus,sizeof(float));
}
A = (float *)calloc(jum_bus,sizeof(float));
B = (float *)calloc(jum_bus,sizeof(float));
C = (float *)calloc(jum_bus,sizeof(float));
D = (float *)calloc(jum_bus,sizeof(float));
E = (float *)calloc(jum_bus,sizeof(float));
F = (float *)calloc(jum_bus,sizeof(float));
for(j=1;j<=jum_bus;j++)
{
A[j]=0;
B[j]=0;
C[j]=0;
D[j]=0;
E[j]=0;
F[j]=0;
}
Ifg2 = (float *)calloc(jum_bus,sizeof(float));
Ifg0 = (float *)calloc(jum_bus,sizeof(float));
Ifb2 = (float *)calloc(jum_bus,sizeof(float));
Ifb0 = (float *)calloc(jum_bus,sizeof(float));
voltfasaG0=(float **)calloc(jum_bus,sizeof(float *));
voltfasaG1=(float **)calloc(jum_bus,sizeof(float *));
voltfasaG2=(float **)calloc(jum_bus,sizeof(float *));
voltfasaB0=(float **)calloc(jum_bus,sizeof(float *));
voltfasaB1=(float **)calloc(jum_bus,sizeof(float *));
voltfasaB2=(float **)calloc(jum_bus,sizeof(float *));
for(i=1;i<=jum_bus;i++)
{
//voltan jujuk zero
voltfasaG0[i]=(float *)calloc(jum_bus,sizeof(float));
voltfasaG1[i]=(float *)calloc(jum_bus,sizeof(float));
//voltan jujuk positif
voltfasaG2[i]=(float *)calloc(jum_bus,sizeof(float));
voltfasaB0[i]=(float *)calloc(jum_bus,sizeof(float));
//voltan jujuk negatif
voltfasaB1[i]=(float *)calloc(jum_bus,sizeof(float));
voltfasaB2[i]=(float *)calloc(jum_bus,sizeof(float));
}
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
//jika kes satu fasa ke bumi
if(n==1)
{
Ifg[g] = (invG[g][g] + gposinv[g][g]*2)/(((invG[g][g] + gposinv[g][g]*2)*(invG[g][g] + gposinv[g][g]*2))+
((invB[g][g]+bposinv[g][g]*2+dot[1].zf)*(invB[g][g]+bposinv[g][g]*2+dot[1].zf)));
Ifb[g] = -(invB[g][g]+bposinv[g][g]*2+dot[1].zf)/(((invG[g][g] + gposinv[g][g]*2)*(invG[g][g] + gposinv[g][g]*2))+
((invB[g][g]+bposinv[g][g]*2+dot[1].zf)*(invB[g][g]+bposinv[g][g]*2+dot[1].zf)));
IfgN[g] = Ifg[g]*(-3);
IfbN[g] = Ifb[g]*(-3);
fprintf(fout,"\n\n\n\n");
fprintf(fout,"A PHASE TO GROUND FAULT\n\n\n");
fprintf(fout,"\tCURRENTS AT FAULT BUS Ifa(0)=Ifa(1)=Ifa(2). CURRENT Ifb=Ifc=0\n");
fprintf(fout,"\n");
fprintf(fout,"\tIfa(real)=%.4f\tIfa(imaginary)=%.4f\n",Ifg[g],Ifb[g]);
fprintf(fout,"\n\n\n");
fprintf(fout,"\tTOTAL FAULT CURRENT 3Ifzero\n\n");
fprintf(fout,"\tIftotal(real)=%.4f\tIftotal(imaginary)=%.4f",IfgN[g],IfbN[g]);
//---------------------------------------------------------------------------------------
for(j=1;j<=jum_bus;j++)
{
//voltan fasa A
voltangagalG0[j][g] = ((-invG[j][g]*Ifg[g])+(invB[j][g]*Ifb[g])) + (1-((gposinv[j][g]*Ifg[g])-(bposinv[j][g]*Ifb[g]))) + ((-gposinv[j][g]*Ifg[g])+(bposinv[j][g]*Ifb[g]));
if(!Ifg[g]==0)
{
voltangagalB0[j][g] = ((-invG[j][g]*Ifb[g])-(invB[j][g]*Ifg[g])) + (1-((-gposinv[j][g]*Ifb[g])-(bposinv[j][g]*Ifg[g]))) + ((-gposinv[j][g]*Ifb[g])-(bposinv[j][g]*Ifg[g]));
}
else
if (Ifg[g]==0 || !Ifg[g]==0)
{
//voltan fasa B
voltangagalG1a[j][g] = ((-invG[j][g]*Ifg[g])+(invB[j][g]*Ifb[g])) + (1-((gposinv[j][g]*Ifg[g])-(bposinv[j][g]*Ifb[g])))*(-0.5) + ((-gposinv[j][g]*Ifg[g])+(bposinv[j][g]*Ifb[g]))*(-0.5);
voltangagalB1a[j][g] = ((-invG[j][g]*Ifb[g])-(invB[j][g]*Ifg[g])) + (1-((-gposinv[j][g]*Ifb[g])-(bposinv[j][g]*Ifg[g])))*(-0.8660) + ((-gposinv[j][g]*Ifb[g])-(bposinv[j][g]*Ifg[g]))*(0.8660);
//voltan fasa C
voltangagalG1b[j][g] = ((-invG[j][g]*Ifg[g])+(invB[j][g]*Ifb[g])) + (1-((gposinv[j][g]*Ifg[g])-(bposinv[j][g]*Ifb[g])))*(-0.5) + ((-gposinv[j][g]*Ifg[g])+(bposinv[j][g]*Ifb[g]))*(-0.5);
voltangagalB1b[j][g] = ((-invG[j][g]*Ifb[g])-(invB[j][g]*Ifg[g])) + (1-((-gposinv[j][g]*Ifb[g])-(bposinv[j][g]*Ifg[g])))*(0.8660) + ((-gposinv[j][g]*Ifb[g])-(bposinv[j][g]*Ifg[g]))*(-0.8660);
}
}
//------------------------------------------------------------
fprintf(fout,"\n\n\n");
fprintf(fout,"\t\t\t\t\t\tVOLTAGES ALL BUSES TO BUS %d \n\n",g);
for(j=1;j<=jum_bus;j++)
{
fprintf(fout,"V%d%dphaseA:%.4f+%.4fj\t",j,g,voltangagalG0[j][g],voltangagalB0[j][g]);
}
fprintf(fout,"\n");
fprintf(fout,"\n");
for(j=1;j<=jum_bus;j++)
{
fprintf(fout,"V%d%dphaseB:%.4f%.4fj\t",j,g,voltangagalG1a[j][g],voltangagalB1a[j][g]);
}
fprintf(fout,"\n");
fprintf(fout,"\n");
for(j=1;j<=jum_bus;j++)
{
fprintf(fout,"V%d%dphaseC:%.4f+%.4fj\t",j,g,voltangagalG1b[j][g],voltangagalB1b[j][g]);
}
fprintf(fout,"\n");
}
else
//---------------------------------------------------------------------------------
//jika kes dua fasa ke bumi
if(n==2)
{
//arus jujuk positif
A[g]=((gposinv[g][g]*(gposinv[g][g] + invG[g][g])) - ((bposinv[g][g]*(bposinv[g][g] + invB[g][g]))) + (invG[g][g]*gposinv[g][g]) - (invB[g][g]*bposinv[g][g]));
B[g]=((gposinv[g][g]*(bposinv[g][g] + invB[g][g])) + ((bposinv[g][g]*(gposinv[g][g] + invG[g][g]))) + (invG[g][g]*bposinv[g][g]) + (invB[g][g]*gposinv[g][g]));
Ifg[g] = (((A[g]*(invG[g][g] + gposinv[g][g])) + ((bposinv[g][g] + invB[g][g])*B[g]))/((A[g]*A[g]) + (B[g]*B[g])));
Ifb[g] = (((A[g]*(bposinv[g][g] + invB[g][g])) - ((invG[g][g] + gposinv[g][g])*B[g]))/((A[g]*A[g]) + (B[g]*B[g])));
fprintf(fout,"\n\n\n\n");
fprintf(fout,"\tTWO PHASE TO GROUND FAULT\n\n");
fprintf(fout,"\tPOITIVE SEQUENCE CURRENT=\treal=%.4f\timaginary=%.4fj\n",Ifg[g],Ifb[g]);
//arus jujuk negatif
C[g]=(((invG[g][g]*(gposinv[g][g]+invG[g][g]))-(invB[g][g]*(bposinv[g][g]+invB[g][g])))/(((gposinv[g][g]+invG[g][g])*(gposinv[g][g]+invG[g][g]))+((bposinv[g][g]+invB[g][g])*(bposinv[g][g]+invB[g][g]))));
D[g]=(((invG[g][g]*(bposinv[g][g]+invB[g][g]))+(invB[g][g]*(gposinv[g][g]+invG[g][g])))/(((gposinv[g][g]+invG[g][g])*(gposinv[g][g]+invG[g][g]))+((bposinv[g][g]+invB[g][g])*(bposinv[g][g]+invB[g][g]))));
Ifg2[g] = ((C[g]*(-Ifg[g])) + (Ifb[g]*D[g]));
Ifb2[g] = ((C[g]*Ifb[g]) + ((-Ifg[g])*D[g]));
fprintf(fout,"\tNEGATIVE SEQUENCE CURRENT=\treal=%.4f\timaginary=%.4fj\n",Ifg2[g],Ifb2[g]);
//arus jujuk zero
E[g]=(((gposinv[g][g]*(gposinv[g][g]+invG[g][g]))-(bposinv[g][g]*(bposinv[g][g]+invB[g][g])))/(((gposinv[g][g]+invG[g][g])*(gposinv[g][g]+invG[g][g]))+((bposinv[g][g]+invB[g][g])*(bposinv[g][g]+invB[g][g]))));
F[g]=(((gposinv[g][g]*(bposinv[g][g]+invB[g][g]))+(bposinv[g][g]*(gposinv[g][g]+invG[g][g])))/(((gposinv[g][g]+invG[g][g])*(gposinv[g][g]+invG[g][g]))+((bposinv[g][g]+invB[g][g])*(bposinv[g][g]+invB[g][g]))));
Ifg0[g] = ((E[g]*(-Ifg[g])) + (Ifb[g]*F[g]));
Ifb0[g] = ((E[g]*Ifb[g]) + ((-Ifg[g])*F[g]));
fprintf(fout,"\tZERO SEQUENCE CURRENT=\treal=%.4f\timaginary=%.4fj\n",Ifg0[g],Ifb0[g]);
fprintf(fout,"\n\n");
IfgN[g]=Ifg0[g]*3;
IfbN[g]=Ifb0[g]*3;
fprintf(fout,"\n\n\n");
fprintf(fout,"\tTOTAL FAULT CURRENT 3Ifzero\n\n");
fprintf(fout,"\tIftotal(real)=%.4f\tIftotal(imaginary)=%.4f",IfgN[g],IfbN[g]);
fprintf(fout,"\n\n\n");
for(j=1;j<=jum_bus;j++)
{
//voltan fasa A
voltfasaG0[j][g] = ((-invG[j][g]*Ifg0[g])+(invB[j][g]*Ifb0[g]));
voltfasaB0[j][g] = ((-invG[j][g]*Ifb0[g])-(invB[j][g]*Ifg0[g]));
voltfasaG1[j][g] = (1-((gposinv[j][g]*Ifg[g])-(bposinv[j][g]*Ifb[g])));
voltfasaB1[j][g] = (1-((gposinv[j][g]*Ifg[g])-(bposinv[j][g]*Ifb[g])));
voltfasaG2[j][g] = ((-gposinv[j][g]*Ifg2[g])+(bposinv[j][g]*Ifb2[g]));
voltfasaB2[j][g] = ((-gposinv[j][g]*Ifg2[g])+(bposinv[j][g]*Ifb2[g]));
}
for(j=1;j<=jum_bus;j++)
{
voltangagalG0[j][g] = voltfasaG0[j][g] + voltfasaG1[j][g] + voltfasaG2[j][g];
voltangagalB0[j][g] = voltfasaB0[j][g] + voltfasaB1[j][g] + voltfasaB2[j][g];
voltangagalG1a[j][g] = voltfasaG0[j][g] + voltfasaG1[j][g]*(-0.5) + voltfasaG2[j][g]*(-0.5);
voltangagalB1a[j][g] = voltfasaB0[j][g] + voltfasaB1[j][g]*(-0.8660) + voltfasaB2[j][g]*(0.8660);
voltangagalG1b[j][g] = voltfasaG0[j][g] + voltfasaG1[j][g]*(-0.5) + voltfasaG2[j][g]*(-0.5);
voltangagalB1b[j][g] = voltfasaB0[j][g] + voltfasaB1[j][g]*(0.8660) + voltfasaB2[j][g]*(-0.8660);
}
fprintf(fout,"\n\n\n");
fprintf(fout,"\t\t\t\t\t\tVOLTAGES ALL BUSES TO BUS %d \n\n",g);
for(j=1;j<=jum_bus;j++)
{
fprintf(fout,"V%d%dphaseA:%.4f+%.4fj\t",j,g,voltangagalG0[j][g],voltangagalB0[j][g]);
}
fprintf(fout,"\n");
fprintf(fout,"\n");
for(j=1;j<=jum_bus;j++)
{
fprintf(fout,"V%d%dphaseB:%.4f%.4fj\t",j,g,voltangagalG1a[j][g],voltangagalB1a[j][g]);
}
fprintf(fout,"\n");
fprintf(fout,"\n");
for(j=1;j<=jum_bus;j++)
{
fprintf(fout,"V%d%dphaseC:%.4f+%.4fj\t",j,g,voltangagalG1b[j][g],voltangagalB1b[j][g]);
}
fprintf(fout,"\n");
}
else
//kes satu fasa ke fasa
if(n==3)
{
//arus fasa zero =0
A[g] = (gposinv[g][g] + gposinv[g][g])*(gposinv[g][g] + gposinv[g][g]);
B[g] = (bposinv[g][g] + bposinv[g][g])*(bposinv[g][g] + bposinv[g][g]);
Ifg0[g]=0;
Ifb0[g]=0;
Ifg[g] = (gposinv[g][g] + gposinv[g][g])/(A[g] + B[g]);
Ifb[g] = -(bposinv[g][g] + bposinv[g][g])/(A[g] + B[g]);
Ifg2[g] = Ifg[g]*(-1);
Ifb2[g] = Ifb[g]*(-1);
IfgN[g] = Ifg0[g]*3;
IfbN[g] = Ifb0[g]*3;
fprintf(fout,"\n\n\n\n");
fprintf(fout,"PHASE TO PHASE FAULT\n\n\n");
fprintf(fout,"\tCURRENT AT FAULT BUS Ifa(0)= 0, Ifa(1)=-Ifa(2)\n");
fprintf(fout,"\n");
fprintf(fout,"\tIfa(real)=%.4f\tIfa(imaginary)=%.4f\n",Ifg[g],Ifb[g]);
fprintf(fout,"\n\n\n");
fprintf(fout,"\tTOTAL FAULT CURRENT 3Ifzero\n\n");
fprintf(fout,"\tIftotal(real)=%.4f\tIftotal(imaginary)=%.4f",IfgN[g],IfbN[g]);
for(j=1;j<=jum_bus;j++)
{
//voltan fasa A
voltfasaG0[j][g] = ((-invG[j][g]*Ifg0[g])+(invB[j][g]*Ifb0[g]));
voltfasaB0[j][g] = ((-invG[j][g]*Ifb0[g])-(invB[j][g]*Ifg0[g]));
voltfasaG1[j][g] = (1-((gposinv[j][g]*Ifg[g])-(bposinv[j][g]*Ifb[g])));
voltfasaB1[j][g] = (1-((gposinv[j][g]*Ifg[g])-(bposinv[j][g]*Ifb[g])));
voltfasaG2[j][g] = ((-gposinv[j][g]*Ifg2[g])+(bposinv[j][g]*Ifb2[g]));
voltfasaB2[j][g] = ((-gposinv[j][g]*Ifg2[g])+(bposinv[j][g]*Ifb2[g]));
}
for(j=1;j<=jum_bus;j++)
{
voltangagalG0[j][g] = voltfasaG0[j][g] + voltfasaG1[j][g] + voltfasaG2[j][g];
voltangagalB0[j][g] = voltfasaB0[j][g] + voltfasaB1[j][g] + voltfasaB2[j][g];
voltangagalG1a[j][g] = voltfasaG0[j][g] + voltfasaG1[j][g]*(-0.5) + voltfasaG2[j][g]*(-0.5);
voltangagalB1a[j][g] = voltfasaB0[j][g] + voltfasaB1[j][g]*(-0.8660) + voltfasaB2[j][g]*(0.8660);
voltangagalG1b[j][g] = voltfasaG0[j][g] + voltfasaG1[j][g]*(-0.5) + voltfasaG2[j][g]*(-0.5);
voltangagalB1b[j][g] = voltfasaB0[j][g] + voltfasaB1[j][g]*(0.8660) + voltfasaB2[j][g]*(-0.8660);
}
fprintf(fout,"\n\n\n");
fprintf(fout,"\t\t\t\t\t\tVOLTAGES ALL BUSES TO BUS %d \n\n",g);
for(j=1;j<=jum_bus;j++)
{
fprintf(fout,"V%d%dphaseA:%.4f+%.4fj\t",j,g,voltangagalG0[j][g],voltangagalB0[j][g]);
}
fprintf(fout,"\n");
fprintf(fout,"\n");
for(j=1;j<=jum_bus;j++)
{
fprintf(fout,"V%d%dphaseB:%.4f%.4fj\t",j,g,voltangagalG1a[j][g],voltangagalB1a[j][g]);
}
fprintf(fout,"\n");
fprintf(fout,"\n");
for(j=1;j<=jum_bus;j++)
{
fprintf(fout,"V%d%dphaseC:%.4f+%.4fj\t",j,g,voltangagalG1b[j][g],voltangagalB1b[j][g]);
}
fprintf(fout,"\n");
}
else
//kes 3 fasa ke bumi @ BALANCED FAULT
if(n==4)
{
float *Voltanreal,*Voltanimag, *Voltanmagnitud, *Voltanangle;
Voltanreal = (float *)calloc(jum_bus+1,sizeof(float));
Voltanimag = (float *)calloc(jum_bus+1,sizeof(float));
Voltanmagnitud = (float *)calloc(jum_bus+1,sizeof(float));
Voltanangle = (float *)calloc(jum_bus+1,sizeof(float));
for(i=1;i<=jum_bus;i++)
{
Voltanreal[i] = 1 - ((gposinv[i][g]*gposinv[g][g]+ bposinv[i][g]*bposinv[g][g])/(gposinv[g][g]*gposinv[g][g]+ bposinv[g][g]*bposinv[g][g]));
Voltanimag[i] = 1 - ((bposinv[i][g]*gposinv[g][g]- gposinv[i][g]*bposinv[g][g])/(gposinv[g][g]*gposinv[g][g]+ bposinv[g][g]*bposinv[g][g]));
Voltanmagnitud[i] = sqrt(Voltanreal[i]*Voltanreal[i] + Voltanimag[i]*Voltanimag[i]);
//Voltanangle[i]= (atan(Voltanimag[i]/ Voltanreal[i])*180)/3.142;
}
fprintf(fout,"\n\n\n");
fprintf(fout,"\t\t\t\t\t\tVOLTAGES ALL BUSES \n\n");
for(i=1;i<=jum_bus;i++)
{
fprintf(fout,"voltan[%d]= %.4f Angle[%d]=%.4f\n",i,Voltanmagnitud[i],i,Voltanmagnitud[i]);
}
}
return 0;
}
ZERO-SEQUENCE INPUT
( file_name : zero.txt ) POSITIVE/NEGATIVE SEQUENCE INPUT
( file_namepos : pos1.txt )
14
11
1 2 1 4 0 0.06 0
2 3 0 0 0 0.60 0
2 5 0 0 0 0.30 0
2 6 0 0 0 0.90 0
3 4 0 0 0 0.80 0
3 6 0 0 0 0.80 0
4 6 0 0 0 1.00 0
4 9 0 0 0 1.10 0
4 10 1 1 0 0.08 0
5 7 0 0 0 0.80 0
6 8 0 0 0 0.95 0
7 8 0 0 0 0.70 0
7 11 1 3 0 0.34 0
8 9 0 0 0 0.90 0
3
1 1 0.06
10 1 0.04
11 1 0.08
0.05
14
11
1 2 0 0.06 0
2 3 0 0.3 0
2 5 0 0.15 0
2 6 0 0.45 0
3 4 0 0.40 0
3 6 0 0.40 0
4 6 0 0.60 0
4 9 0 0.70 0
4 10 0 0.08 0
5 7 0 0.43 0
6 8 0 0.48 0
7 8 0 0.35 0
7 11 0 0.10 0
8 9 0 0.48 0
3
1 1 0.20
10 1 0.15
11 1 0.25
adik1310
|
|
|
|