Computer Methods in Power System Lab
Computer Methods in Power System Lab
ELECTRICAL ENGINEERING
ALGORITHM:1
OBJECTIVE:-
Develop a program to solve a set of four simultaneous linear
equation using Gaussian elimination
Algorithm:-
(5) r=a[i][0]/a[0][0]
(6) a[1][i]=a[1][i]-a[0][i]*r2
(7) r2=a[2][0]/a[0][0]
(8) a[2][i]=a[2][i]-a[i][1]*r3
(10) z=a[3][3]/a[2][2]
(11) y=a[1][3]-(a[1][2]*z/a[1][1])
(12) x=a[0][3]-a[0][2]*z-a[0][1]*y/[0][0]
PROGRAM NO: 1
/*Program to solve a set of simultaneous linear equation
using Gauss Elimination Method */
#include<stdio.h>
#include<conio.h>
#include<process.h>
void main()
{
float a[3][4],r1,r2,r3,x,y,z;
int i;
clrscr();
printf("\n\n GAUSS ELIMINATION METHOD");
printf("\n\n Equation is in the form ax+by+cz=d\n");
printf("\n\n ENTER the cofficints of x,y,z and enter d");
for(i=0;i<=3;i++)
{
printf("\n\n enter the %d row:\n",i+1);
scanf("%f%f%f%f",&a[i][1],&a[i][2],&a[i][3]);
}
if(a[0][0]==0)
{
printf("\n as first value of x is '0' ");
printf("so this method cannot be implemented::::::");
getch();
exit(0);
}
else
{
r1=a[1][0]/a[0][0];
for(i=0;i<=3;i++)
{
a[1][i]=a[1][i]-a[0][i]*r1;
r2=a[2][0]/a[0][0];
for(i=0;i<=3;i++)
{
a[2][i]=a[2][i]-a[1][i]*r2;
}
r3=a[2][1]/a[1][1];
for(i=0;i<=3;i++)
{
a[2][i]=a[2][i]-a[1][i]*r2;
}
z=a[2][3]/a[2][2];
y=a[1][3]-(a[1][2]*z)/a[1][1];
x=a[0][3]-(a[0][2]*z)-(a[0][1]*y)/a[0][0];
printf("\n x:%f",x);
printf("\n y:%f",y);
printf("\n z:%f",z);
getch();
}
}
}
OUTPUT:
X: 1.6437887
Y: 1.140845
Z: 2.2084507
ALGORITHM:2
OBJECTIVE:-
Write a program to formulate ybus by non singular transformation
ybus=[A]t[y][A]
Algorithm:-
#include<stdio.h>
#include<conio.h>
void main ()
{
int incd[100][100],yprm[100][100],tincd[100][100];
int i,j,k,m,n,rw,cl;
static int ybus[100][100],c[100][100];
clrscr();
printf("enter the no. of rows incidence matrix: ");
scanf("%d",&m);
printf("enter the no. of colums incidence matrix: ");
scanf("%d",&n);
printf("\nenter the element of incidence matrix: ");
cl=8;
for(i=0;i<m;i++)
{
rw=4;
for(j=0;j<n;j++)
{
gotoxy(rw,cl);
scanf("%d",&incd[i][j]);
rw=rw+4;
}
cl=cl+3;
printf("\n\n press any key to continue ");
getch();
clrscr();
//
printf("\n enter the element of primitive admittance matrix");
cl=8;
for(i=0;i<m;i++)
{
rw=4;
for(j=0;j<m;j++)
{
gotoxy(rw,cl);
scanf("%d",&yprm[i][j]);
rw=rw+4;
}
cl=cl+3;
}
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
tincd[i][j]=incd[i][j];
}
printf("\n\npress any key to continue..");
getch();
clrscr();
//
printf("the transpose of primitive incidence matrix is");
cl=8;
for(i=0;i<n;i++)
{
rw=4;
for(j=0;j<m;j++)
{
gotoxy(rw,cl);
printf("%d",&yprm[i][j]);
rw=rw+4;
}
cl=cl+3;
//multiplying.......
for(i=0;i<n;i++)
{
for(k=0;k<m;k++)
{
for(j=0;j<m;j++)
c[i][j]=c[i][j]+tincd[i][j]*yprm[j][k];
}
}
//calculate
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
for(k=0;k<n;k++)
ybus[i][j]=ybus[i][j]+c[i][j]*incd[k][j];
}
}
printf("\n\npress any key to continue");
getch();
clrscr();
//
printf("the bus admittance matrix is");
cl=8;
for(i=0;i<m;i++)
{
rw=4;
for(j=0;j<n;j++)
{
gotoxy(rw,cl);
printf("%d",ybus[i][j]);
rw=rw+6;
}
cl=cl+3;
}
printf("\n\npress any key to exit");
getch();
}
}
}
OUTPUT:
3 2
1 7
98 154
249 546
ALGORITHM:3
OBJECTIVE:
Develop a program to do the following mathematical operation
Algorithm:
(1) enter the condition of switch statement
(2) enter the choice
(3) enter the no of rows in the matrix
(4) enter the no of columns in the matrix
(5) print enter the matrix
(6) logic to calculate transpose of a matrix
c[i][j]=a[i][j]
(7) enter case 2
(8) enter the same no rows and columns in the matrix
(9) logic of adding two matrix
(10) enter case 3
(11) enter the same no rows and columns in the matrix
(12) logic of subtraction of two matrix
(13) c[i][j]=a[i][j]-b[i][j]
(14) enetr case 4
(15) enter the same no rows and columns in the matrix
(16) logic to calculate product of two matrices
(17) c[i][j]=c[i][j]+a[i][j]*b[j][k]
(18) print the result
(19) stop
PROGRAM NO: 3
/* Program to do the following mathematical operation
(1) Transpose of a matrix
(2) Multiplication of two matrices
(3) Addition of two matrices
(4) Subtraction of two matrices */
#include<stdio.h>
#include<conio.h>
#include<process.h>
void main ()
{
int a[25][25],b[25][25];
static int c[25][25];
int i,j,l,m,n,o,p,k,ch,rw,cl;
clrscr();
printf("\n\n press 1:: to calculate the transposs of a matrices!");
printf("\n\n press 2:: to add two matrices matrices!");
printf("\n\n press 3:: to sustract two matrices! ");
printf("\n\n press 4:: to multiply two matrices! ");
printf("\n\n press 5:: to exit from the program!");
printf("\n\n enter your choice(between 1 to 5):::::: ");
scanf("%d",&ch);
clrscr();
switch(ch)
{
case 1:
printf("\nenter the no. of rows in the matrix:: ");
scanf("%d",&m);
printf("\nenter the no. of columns in the matrix:: ");
cl=8;
for(i=0;i<m;i++)
{
rw=10;
for(j=0;j<n;j++)
{
gotoxy(rw,cl);
scanf("%d",&a[i][j]);
rw=rw+5;
}
cl=cl+3;
}
clrscr();
printf("::the transpose of the matrix is :: ");
cl=3;
for(i=0;i<n;i++)
{
rw=10;
for(j=0;j<m;j++)
{
c[i][j]=a[i][j];
gotoxy(rw,cl);
printf("%d",c[i][j]);
rw=rw+5;
}
cl=cl+3;
}
getch();
break;
case 2:
printf("\n\nenter the no. of rows in the first matrix:: ");
scanf("%d",&m);
printf("\nenter the no. of columns in the first matrix:: ");
scanf("%d",&n);
printf("\nenter the no. of rows in the second matrix:: ");
scanf("%d",&p);
printf("\nenter the no. of columns in the second matrix:: ");
scanf("%d",&o);
clrscr();
if(m==p&&n==0)
{
printf("\n::enter the first matrix::");
cl=3;
for(i=0;i<m;i++)
{
gotoxy(rw,cl);
scanf("%d",&a[i][j]);
rw=rw+5;
}
cl=cl+3;
}
clrscr();
printf("\n:: enter the second matrix::");
cl=3;
for(i=0;i<m;i++)
{
rw=10;
for(j=0;j<n;j++)
{
gotoxy(rw,cl);
scanf("%d",&b[i][j]);
rw=rw+5;
}
cl=cl+3;
}
clrscr();
// logic to add two matrices
printf("::the sum of the two matrices is:: ");
cl=3;
for(i=0;i<m;i++)
{
rw=10;
for(j=0;j<n;j++)
{
c[i][j]=a[i][j]+b[i][j];
gotoxy(rw,cl);
printf("%d",c[i][j]);
rw=rw+5;
}
cl=cl+3;
}
else
printf("the sum can not be found");
getch();
break;
case 3:
printf("\nenter the no. of rows in the first matrix:: ");
scanf("%d",&m);
printf("\nenter the no. of columns in the first matrix:: ");
scanf("%d",&n);
printf("\nenter the no. of rows in the second matrix:: ");
scanf("%d",&p);
printf("\nenter the no. of columns in the second matrix:: ");
scanf("%d",&o);
clrscr();
if(m==p&&n==o)
{
printf("\n::enter the first matrix::");
cl=3;
for(i=0;i<m;i++)
{
rw=10;
for(j=0;j<n;j++)
{
gotoxy(rw,cl);
scanf("%d",a[i][j]);
rw=rw+5;
}
cl=cl+3;
}
clrscr();
printf("\nenter the second matrix: ");
cl=3;
for(i=0;i<m;i++)
{
rw=10;
for(j=0;j<n;j++)
{
gotoxy(rw,cl);
scanf("%d",&b[i][j]);
rw=rw+5;
}
cl=cl+3;
}
clrscr();
// logic to obtain the difference of two matrices
printf("the differnce of two matrices is: ");
cl=3;
for(i=0;i<m;i++)
{
rw=10;
for(j=0;j<n;j++)
{
c[i][j]=a[i][j]-b[i][j];
gotoxy(rw,cl);
printf("%d",c[i][j]);
rw=rw+5;
}
cl=cl+3;
}
}
else
printf("the sum can not be found");
getch();
break;
case 4;
printf("\n\n enter the no. of rows in the first matrix:: ");
scanf("%d",&m);
printf("\n enter the no. of columns in the first matrix:: ");
scanf("%d",&n);
printf("\n enter the no. of columns in the second matrix:: ");
scanf("%d",&p);
printf("\n enter the no. of columns in the second matrix:: ");
scanf("%d",&o)
clrscr();
if(n==p)
{
printf("\n enter the first matrix: ");
cl=3;
for(i=0;i<m;i++)
{
gotoxy(rw,cl)
scanf("%d",&a[i][j]);
rw=rw+5;
}
cl=cl+3;
}
clrscr();
printf("\n enter the second matrix: ");
cl=3;
for(i=0;i<m;i++)
{
rw=10;
for(j=0;j<n;j++);
{
cl=cl+3;
}
clrscr();
// logic to multiply the two matrices
cl=3;
for(i=0;i<m;i++)
{
for(k=0;k<o;k++)
{
for(j=0;j<n;j++)
c[i][j]=c[i][k]+a[i][j]*b[j][k];
}
}
printf("::the product of the two matrices is :: ");
for(i=0;i<m;i++)
{
rw=10;
for(j=0;j<o;j++)
{
gotoxy(rw,cl);
printf("%d",c[i][j]);
rw=rw+5;
}
cl=cl+3;
}
}
else
printf("the product could not be found");
getch();
break;
case 5: exit(0);
OUTPUT:
press 1: to calculate the transpose
press 2: to add two matrices
press 3: to subtract two matrices
press 4: to multiply two matrices
press 5: to exit
OBJECTIVE:
You have been giving with network data consisting of element no, starting
node and end node .Develop a program to make element node and convert it into
ybus incidence matrix A by choosing any bus as reference
Algorithm:-
#include<stdio.h>
#include<conio.h>
void main ()
{
clrscr();
int a,i,j,e,s,rw,cl;
static st[100],end[100],incd[100][100];
printf("enter the number of nodes in the graph: ");
scanf("%d", &e);
printf("\nenter the number of element in the graph: ");
scanf("%d",&s);
printf("\nenter the starting node : ");
printf("\n\n");
for(i=0;i<s;i++)
scanf("%d",&st[i]);
printf("\n enter the end node ");
printf("\n\n");
// logic for formation of element node incidence matrix
for (i=0;i<s;i++)
{
for(j=0;j<e;j++)
{
if(j==st[i])
incd[i][j]=+1;
if(j==end[i])
incd[i][j]=-1;
}
}
clrscr();
printf("\n the element node incidence matrix");
cl=5;
for(i=0;i<s;i++)
{
rw=8;
for(j=0;j<e;j++)
{
gotoxy(rw,cl);
printf("%d",incd[i][j]);
rw=rw+5;
}
cl=cl+3;
getch();
printf("\n\n enter the refernce node: ");
scanf("%d",&a);
clrscr();
printf("the bus incidence matrix is: ");
// logic to form the bus incidence matrix
cl=5;
for(i=0;i<s;i++)
{
rw=8;
for(j=0;j<s;j++)
{
if(j==a)
j=j+1;
gotoxy(rw,cl);
printf("%d",incd[i][j]);
rw=rw+5;
}
cl=cl+3;
}
printf("\n\n\n press any key to exit");
getch();
}
getch();
}
OUTPUT:
OBJECTIVE: -
The gauss seidel method is also known as method of successive
displacement use the gauss seidel method to find the solution following equation.
Algorithm:-
#include<stdio.h>
#include<conio.h>
void main ()
{
float a1,b1,c1,d1,a2,b2,c2,d2,a3,b3,c3,d3,x,y,z,x0,y0,z0;
int i;
printf("\ngauss sidel method");
printf("\n\nequation is of the formax by cz=d\n");
printf("enter the cofficient of x,y,z and enter d");
printf("\nenter the first row:\n");
scanf("%f%f%f%f",&a1,&b1,&c1,&d1);
printf("\nenter the second row:\n");
scanf("%f%f%f%f",&a2,&b2,&c2,&d2);
printf("\nenter the third row:\n");
scanf("%f%f%f%f",&a3,&b3,&c3,&d3);
printf("enter the initial value of x");
scanf("%f",&x0);
printf("enter the initial value of y");
scanf("%f",&y0);
printf("enter the initial value of z");
scanf("%f",&z0);
for(i=0;i<4;i++)
{
x0=(d1-b1*y0-c1*z0)/a1;
y0=(d2-a2*y0-c2*z0)/b2;
z0=(d3-a3*y0-b3*z0)/a3;
printf("\nx=%f\ty=%f\tz=%f",x0,y0,z0);
}
getch();
}
OUTPUT:
1
1
-6
-12
enter the third row
3
-1
-1
4
enter the intial value of x:0
enter the intial valve of y:0
enter the intial valve of z:0
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int b,i,s,t,j=0;
float a,c,d,sum=0;
clrscr();
printf("enter the initial demand in GW:");
scanf("%d",&b);
printf("\nenter the average growth rate:");
scanf("%f",&a);
printf("\nenter the starting year:");
scanf("%d",&s);
printf("enter the final year:");
scanf("%d",&t);
/*logic to find out yearly demand*/
for(i=s;i<=t;i++)
{
a=b*(exp(a*j));
printf("\n\n the demand for year %d in gw is %f",i,c);
sum=sum+c;
j=j+1;
}
/*logic to calculate average demand*/
d=sum/j;
printf("\n\n the average yearly in gw is %f",d);
printf("\n\n press any key to exit!!");
getch();
}
OUTPUT:-