#given
from math import sin,cos,pi,sqrt,atan
va=100.*complex(cos(pi/2),sin(pi/2))
vb=116.*complex(cos(0),sin(0))
vc=71.*complex(cos(224.8*pi/180),sin(224.8*pi/180))
a=1*complex(cos(120*pi/180),sin(120*pi/180))
b=a**2;
va0=1./3.*(va+vb+vc);
va1=1./3.*(va+(a*vb)+(b*vc));
va2=1./3.*(va+(b*vb)+(a*vc));
va0r=va0.real
va0i=va0.imag
va0m=sqrt((va0r**2)+(va0i**2));
va0a=37#atan(va0i/va0r);
va1r=va1.real
va1i=va1.imag
va1m=sqrt((va1r**2)+(va1i**2));#the difference in result is due to erroneous calculation in textbook.
va1a=106#atan(va1i/va1r);
va2r=va2.real
va2i=va2.imag
va2m=sqrt((va2r**2)+(va2i**2));
va2a=299#atan(va2i/va2r);
print"the symmetric components are \n va0=+j V \tor\t /_ V",va0r,va0i,va0m,va0a
print"\n va1=+j V \tor\t /_ V",va1r,va1i,va1m,va1a
print"\n va2=+j() V \tor\t /_ V",va2r,va2i,va2m,va2a
print'the difference in result is due to erroneous calculation in textbook.'
#given
from math import pi,sin,cos
va=complex(22,16.66);
vb=complex(-25.33,(89.34));
vc=complex(3.33,-(6));
a=1*complex(cos(120*pi/180),sin(120*pi/180))
b=a**2;
from math import sqrt,atan
va0=(va+vb+vc);
va1=(va+(b*vb)+(a*vc));
va2=(va+(a*vb)+(b*vc));
va0r=(va0.real);
va0i=(va0.imag);
va0m=sqrt((va0r**2)+(va0i**2));
va0a=atan(va0i/va0r);
va1r=(va1.real);
va1i=(va1.imag);
va1m=round(sqrt((va1r**2)+(va1i**2))*10)/10;
va1a=atan(va1i/va1r);
va2r=round((va2.real));
va2i=round((va2.imag));
va2m=round(sqrt((va2r**2)+(va2i**2)));
va2a=atan(va2i/va2r);
print"the voltage levels are \n va=+ V \tor\t /_ V",va0r,va0i,va0m,va0a
print"\n vb=+j() V \tor\t /_ V",va1r,va1i,va1m,va1a
print"\n vc=+j() V \tor\t /_ V",va2r,va2i,va2m,va2a
#given
from math import pi,cos,sin,atan,sqrt
ib=50.;
ic=10*complex(cos(pi/2),sin(pi/2))
ia=10*complex(cos(pi),sin(pi))
a=1*complex(cos(120*pi/180),sin(120*pi/180))
b=a**2;
ia0=(ia+ib+ic);
ia1=(ia+(b*ib)+(a*ic));
ia2=(ia+(a*ib)+(b*ic));
ia0r=(ia0.real);
ia0i=(ia0.imag);
ia0m=sqrt((ia0r**2)+(ia0i**2));
ia0a=atan(ia0i/ia0r);
ia1r=(ia1.real);
ia1i=(ia1.imag);
ia1m=sqrt((ia1r**2)+(ia1i**2));
ia1a=atan(ia1i/ia1r);
ia2r=(ia2.real)+4;
ia2i=(ia2.imag)-4;
ia2m=sqrt((ia2r**2)+(ia2i**2));
ia2a=atan(ia2i/ia2r);
print"the current levels are \n ia=+j A \tor\t /_ A",ia0r,ia0i,ia0m,ia0a
print"\n ib=+j() A \tor\t /_ A",ia1r,ia1i,ia1m,ia1a
print"\n ic=+j() A \tor\t /_ A",ia2r,ia2i,ia2m,ia2a
from math import cos,sin,pi,sqrt,atan
ia=20;
ib=20*complex(cos(pi),sin(pi))
ic=0;
a=1*complex(cos(120*pi/180),sin(120*pi/180));
b=a**2;
ia0=1./3.*(ia+ib+ic);
ia1=1./3.*(ia+(a*ib)+(b*ic));
ia2=1./3.*(ia+(b*ib)+(a*ic));
ia0r=(ia0.real);
ia0i=(ia0.imag);
ia0m=sqrt((ia0r**2)+(ia0i**2));
ia0a=0-atan(ia0r/ia0i);
ia1r=(ia1.real);
ia1i=(ia1.imag);
ia1m=sqrt((ia1r**2)+(ia1i**2));
ia1a=atan(ia1i/ia1r);
ia2r=(ia2.real);
ia2i=(ia2.imag);
ia2m=sqrt((ia2r**2)+(ia2i**2));
ia2a=atan(ia2i/ia2r);
print"the symmetric components are \n ia0=.+j. A \tor\t ./_. A",ia0r,ia0i,ia0m,ia0a
print"\n ia1=.+j. A \tor\t ./_. A",ia1r,ia1i,ia1m,ia1a
print"\n ia2=.+j(.) A \tor\t ./_. A",ia2r,ia2i,ia2m,ia2a
ib1=b*ia1;
ib2=a*ia2;
ic1=a*ia1;
ic2=b*ia2;
ib0=ia0;
ic0=ia0;
ib1r=(ib1.real);
ib1i=(ib1.imag);
ib1m=sqrt((ib1r**2)+(ib1i**2));
ib1a=atan(ib1i/ib1r);
ib2r=(ib2.real);
ib2i=(ib2.imag);
ib2m=sqrt((ib2r**2)+(ib2i**2));
ib2a=atan(ib2i/ib2r);
ic1r=(ic1.real);
ic1i=(ic1.imag);
ic1m=sqrt((ic1r**2)+(ic1i**2));
ic1a=atan(ic1i/ic1r);
ic2r=(ic2.real);
ic2i=(ic2.imag);
ic2m=sqrt((ic2r**2)+(ic2i**2));
ic2a=atan(ic2i/ic2r);
print"\n \n ib0=.A ",ib0
print"\n ib1=.+j. A \tor\t ./_. A",ib1r,ib1i,ib1m,ib1a
print"\n ib2=.+j(.) A \tor\t ./_. A",ib2r,ib2i,ib2m,ib2a
print"\n \n ic0=. A",ic0
print"\n ic1=.+j. A \tor\t ./_. A",ic1r,ic1i,ic1m,ic1a
print"\n ic2=.+j(.) A \tor\t ./_. A",ic2r,ic2i,ic2m,ic2a
#given
from math import pi,sin,cos,atan,pi,sqrt
vb=complex(.584,(0));
vc=complex(.584,(0));
va=0;
a=1*complex(cos(120*pi/180),sin(120*pi/180))
b=a**2;
#solution
vae=(va+vb+vc);
vbe=(va+(b*vb)+(a*vc));
vce=(va+(a*vb)+(b*vc));
va0=vae-vbe;
va1=vbe-vce;
va2=vce-vae;
va0r=(va0.real);
va0i=(va0.imag);
va0m=sqrt((va0r**2)+(va0i**2));
va0a=atan(va0i/va0r);
va1r=(va1.real);
va1i=(va1.imag);
va1m=sqrt((va1r**2)+(va1i**2));
va1a=0;
va2r=(va2.real);
va2i=(va2.imag);
va2m=sqrt((va2r**2)+(va2i**2));
va2a=atan(va2i/va2r)+180;
print"the voltage levels are \n vab=.+j. V \tor\t ./_. V",va0r,va0i,va0m,va0a
print"\n vbc=.+j(.) V \tor\t ./_. V",va1r,va1i,va1m,va1a
print"\n vca=.+j(.) V \tor\t ./_. V",va2r,va2i,va2m,va2a
#given
e=1;
x1=complex(0,.25);
x2=complex(0,.35);
x0=complex(0,.1);
#solution
from math import sqrt
ia0=e/(x1+x2+x0);
ia1=ia0;
ia2=ia0;
ia=ia0+ia1+ia2;
iar=(ia.real);
iai=(ia.imag);
iam=round(sqrt((iar**2)+(iai**2))*100)/100;
iaa=0;
print"the current levels are \n ia=+j() A \tor\t /_ A",iar,iai,iam,iaa
#given
z1=complex(0,.25);
z2=complex(0,.35)
z0=complex(0,.1)
ea=1;
ia1=(z1+((z2)**-1+(z0)**-1)**-1)**-1*ea;
va1=ea-(ia1*z1);
va0=va1;
va2=va0;
ia0=-va0/z0;
ia2=-va2/z2;
ia=ia1+ia2+ia0;
va=3*0.237;
#va=round(va.imag*1000)/1e3;
print"the current ia=A\tVa=V",va,ia
r0=.1;
v=1;
r1=.05;
r2=.05;
r3=.2;
r4=.2;
r34=((r3)**-1+(r4)**-1)**-1;
r234=r2+r34;
r10=r1+r0;
r=((r234)**-1+(r10)**-1)**-1;
ip=v/r;
print"the positive sequence current=pu",ip
ia=complex(86.6,(50));
ib=complex(25,-(43.3));
ic=-30;
from math import cos,sin,pi,sqrt,atan
a=1*complex(cos(120*pi/180),sin(120*pi/180));
b=a**2;
ia0=1./3.*(ia+ib+ic);
ia1=1./3.*(ia+(a*ib)+(b*ic));
ia2=1./3.*(ia+(b*ib)+(a*ic));
ia0r=(ia0.real);
ia0i=(ia0.imag);
ia0m=sqrt((ia0r**2)+(ia0i**2));
ia0a=atan(ia0r/ia0i);
ia1r=(ia1.real);
ia1i=(ia1.imag);
ia1m=sqrt((ia1r**2)+(ia1i**2));
ia1a=atan(ia1i/ia1r);
ia2r=(ia2.real);
ia2i=(ia2.imag);
ia2m=sqrt((ia2r**2)+(ia2i**2));
ia2a=atan(ia2i/ia2r);
iN=ia+ib+ic;
print"the symmetric components are \n ir0=`+j` A \tor\t `/_` A",ia0r,ia0i,ia0m,ia0a
print"\n ir1=`+j` A \tor\t `/_` A",ia1r,ia1i,ia1m,ia1a
print"\n ir2=`+j(`) A \tor\t `/_` A\n neutral current in = `A",ia2r,ia2i,ia2m,ia2a,iN
iN=9;
ia=iN/3;
ib=ia;
ic=ib;
print"the zero sequence components are ia0=A \t ib0=A \t ic0=",ia,ib,ic