Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Reqiurement of MATLAB code from C language code

1 visualización (últimos 30 días)
nishitha
nishitha el 30 de Abr. de 2015
Editada: John D'Errico el 30 de Abr. de 2015
sir/madam we have a C language code with us and need to generate a matlab code for that.Iam sendng the code for which we need matlab code so please kindly mail us back as soon as possible as it is very very very important for us. //PROGRAM FOR THE CALCULATION OF POWER TRANSFER DISTRIBUTUION FACTORS
// I/P FILE:11BUS.IN
#include<conio.h> #include<math.h> #include<stdio.h> #define n1 60 #define nl 100 #define pi 3.14 #define base 100.0
void main() {
FILE *ip,*op;
char ipf[20],opf[20];
int n,nline,nslack,i,j,k,min,k1,i2,j2,m2,n2,ku,p0,q0,
p,q,lp[nl],lq[nl],nc[nl],Nt,M,N;
float x[nl],X[n1][n1],Pmax[nl],P[n1],theta[n1],Pf[nl],Pfnew[nl];
float ATC,B[n1][n1],B1[n1][n1],FACT,sum1,PTDF[nl],pgen[n1],pload[n1];
printf("\n\nENTER THE INPUT FILE NAME\n");
scanf("%s",ipf);
printf("\n\nENTER THE OUTPUT FILE NAME\n\n");
scanf("%s",opf);
ip=fopen(ipf,"r+");
op=fopen(opf,"w+");
fscanf(ip,"%d %d %d",&n,&nline,&nslack);
for(k=1;k<=nline;k++)
fscanf(ip,"%d %d %d %f %f",&lp[k],&lq[k],&nc[k],&x[k],&Pmax[k]);
for(i=1;i<=n;i++)
fscanf(ip,"%f %f",&pgen[i],&pload[i]);
//cal x for the interface..........
//print the data...............
fprintf(op,"\n\n\t -------------------- OUTPUT FILE OF PTDF FOR 11BUS.IN ---------------------\n\n\n");
fprintf(op,"\n%d\n%d\n%d\n\n",n,nline,nslack);
for(k=1;k<=nline;k++) fprintf(op,"\n%d\t %d\t %d\t %d\t %f\t %f",k,lp[k],lq[k],nc[k],x[k],Pmax[k]);
fprintf(op,"\n\n\n\n");
for(i=1;i<=n;i++)
fprintf(op,"\n %d\t %f\t %f",i,pgen[i],pload[i]);
// formation of the B matrix.............
for(k=1;k<=nline;k++)
x[k]=x[k]/nc[k];
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
B[i][j]=0.0;
for(k=1;k<=nline;k++)
{
p=lp[k];
q=lq[k];
B[p][p]=B[p][p]+(1.0/x[k]);
B[q][q]=B[q][q]+(1.0/x[k]);
B[p][q]=B[p][q]-(1.0/x[k]);
B[q][p]=B[q][p]-(1.0/x[k]);
}
fprintf(op,"\n\n\t -------------------- B MATRIX ---------------------\n\n\n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
/* if(B[i][j]==0)
fprintf(op,"\t");
else
fprintf(op," ");*/
fprintf(op,"%f\t",B[i][j]);
}
fprintf(op,"\n");
}
B[nslack][nslack]=1e20;
// X matrix calculations..............
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
B1[i][j]=B[i][j];
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
X[i][j]=0.0;
for(i=1;i<=n;i++)
X[i][i]=1.0;
for(i=1;i<=n;i++)
{
FACT=B[i][i];
for(j=1;j<=n;j++)
{
B[i][j]=B[i][j]/FACT;
X[i][j]=X[i][j]/FACT;
}
for(k=1;k<=n;k++)
{
if(k!=i)
{
FACT=B[k][i];
for(j=1;j<=n;j++)
{
B[k][j]=B[k][j]-FACT*B[i][j];
X[k][j]=X[k][j]-FACT*X[i][j];
}
}
}
}
fprintf(op,"\n\n\t -------------------- X MATRIX ---------------------\n\n\n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
if(X[i][j]==0)
fprintf(op,"\t");
else
fprintf(op," ");
fprintf(op,"%f\t",X[i][j]);
}
fprintf(op,"\n");
}
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
B[i][j]=B1[i][j];
//Pinj calculations...............................
fprintf(op,"\n\n the P INJECTIONS ARE..................\n\n");
for(i=1;i<=n;i++)
{
pgen[i]=pgen[i]/base;
pload[i]=pload[i]/base;
P[i]=pgen[i]-pload[i];
fprintf(op,"Pinj[%d]=%f\n",i,P[i]);
}
// theta calculations............................
fprintf(op,"\n\n the THETA values are .................\n\n");
for(i=1;i<=n;i++)
theta[i]=0.0;
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
theta[i]=theta[i]+X[i][j]*P[j];
}
}
for(i=1;i<=n;i++)
fprintf(op,"theta[%d]=%f\n",i,theta[i]);
// power flows calculations.........................
fprintf(op,"\n\n the POWER FLOWS ARE..................\n\n"); for(k=1;k<=nline;k++) { p=lp[k]; q=lq[k]; Pf[k]=(theta[p]-theta[q])/x[k]; }
for(k=1;k<=nline;k++)
fprintf(op,"\nPij[%d]=%f\n",k,Pf[k]);
//PTDF calculations...................
printf("\n\nENTER THE NO. OF TRANSACTIONS U WANT TO PERFORM:\n\n");
scanf("%d",&Nt);
printf("\nENTER THE SELLER BUSES:\n\n");
scanf("%d",&M);
printf("\nENTER THE BUYER BUSES:\n\n");
scanf("%d",&N);
fprintf(op,"\n\n\t\t------------- POWER TRANSFER DISTRIBUTION FACTORS ----------------\n\n");
for(k=1;k<=nline;k++)
{
p=lp[k];
q=lq[k];
PTDF[k]=(X[p][M]-X[q][M]-X[p][N]+X[q][N])/x[k];
fprintf(op,"\nPTDF[%d]=%f\n",k,PTDF[k]);
}
fprintf(op,"\n\n\t\t------------- NEW POWER TRANSACTIONS ----------------\n\n");
for(k=1;k<=nline;k++)
Pmax[k]=Pmax[k]/100.0;
for(k=1;k<=nline;k++)
{
if(PTDF[k]!=0.0)
{
if(PTDF[k]<0.0)
Pfnew[k]=(-Pmax[k]-Pf[k])/PTDF[k];
else
Pfnew[k]=(Pmax[k]-Pf[k])/PTDF[k];
}
if(PTDF[k]==0.0)
Pfnew[k]=1e20;
}
for(k=1;k<=nline;k++)
fprintf(op,"\nPfnew[%d]=%f\n",k,Pfnew[k]);
min=1;
for(k=2;k<=nline;k++)
{
if(k!=11)
{
if(fabs(Pfnew[k])<fabs(Pfnew[min]))
min=k;
}
}
ATC=Pfnew[min];
fprintf(op,"\n\n the ATC for the given %d to %d transaction is..........=%f\n",M,N,ATC);
fprintf(op,"\n\n The Line in which min POWER flows.......=%d",min);
fclose(ip); fclose(op); }
  1 comentario
John D'Errico
John D'Errico el 30 de Abr. de 2015
Editada: John D'Errico el 30 de Abr. de 2015
I'm sorry, but this is not a MATLAB code writing service. That you need it is not important. If you need it, then either learn MATLAB, or hire someone who knows the language. But this site is not a place to advertise for that purpose either.

Respuestas (0)

La pregunta está cerrada.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by