% Vztazny vykon [MVA]]
Sv=255

% Vztazne napeti [kV]]
Uv=215

% Napeti jemnovite na vedeni [kV]]
Uns=248

% Napeti jemnovite generatoru vedeni [kV]]
Ung=10.5;

% Transformator T1 Snt1 360 MVA, Uk1 12%, p1 Ung/Uns kV
Snt1=360
Uk1=12
p1=Ung/Uns
Xt1=(Uk1/100)*(Uns^2/Snt1)*(Sv/Uv^2)
pause 

% Transformator T2 Snt2 340 MVA, Uk2 12%, p2 220/121 kV
Snt2=340
Uk2=12
p2=220/121
Xt2=(Uk2/100)*(220^2/Snt2)*(Sv/Uv^2)
pause 

% Napeti site
Us=118/Uv*p2

% Vykony dodavane do site Ps 220 MW, CosFi 0.9
Ps=225/Sv
Qs=Ps*tan(acos(0.9))
pause

% Generator Sng 400 MVA, Ung 10.5 kV, Xdc 23.5%, X2 16.4 %
Sng=400;
Xdc=(23.5/100)*(Ung^2/Sng)*(Sv/Uv^2)*(Uns^2/Ung^2)
X2=(16.4/100)*(Ung^2/Sng)*(Sv/Uv^2)*(Uns^2/Ung^2)
Tm=7*Sng/Sv
pause 

% Vedeni Xv 0.4 Ohm/km
delka=255
Xv=0.5*delka*0.4*(Sv/Uv^2)
Xv0=3*Xv

% Zatez Pz 50 MW CosFi 0.85
Pz=50/Sv
Qz=Pz*tan(acos(0.85))
pause

% Vnejsi reaktance
Xvn=Xt1+Xv+Xt2

% Svorkove napeti generatoru
Ug=sqrt((Us+Xvn*Qs/Us)^2+(Xvn*Ps/Us)^2)
FiS=atan((Xvn*Ps/Us)/(Us+Xvn*Qs/Us))*180/pi
FiS2=asin((Xvn*Ps/Us)/Ug)*180/pi

% Impedance zateze
Zz=Ug^2/(Pz-i*Qz)

% Jalove ztraty na vnejsi reaktanci
deltaQvn=Xvn*(sqrt(Ps^2+Qs^2)/Us)^2

% Vystupni vykon generatoru
Pg=Pz+Ps
Qg=Qz+Qs+deltaQvn
Sg=Pg+i*Qg

% Prechodne elektromotoricke napeti generatoru
Uec=sqrt((Ug+Xdc*Qg/Ug)^2+(Xdc*Pg/Ug)^2)
deltaFi=atan((Xdc*Pg/Ug)/(Ug+Xdc*Qg/Ug))*180/pi
deltaFi2=asin((Xdc*Pg/Ug)/Uec)*180/pi

% Uhel mezi Uec a Us
Fi=FiS+deltaFi

% Vlastni a vzajemne vypoctove impedance a admitance
% Bezporuchovy stav
Z11=i*Xdc+i*Xvn*Zz/(i*Xvn+Zz)
Y11=1/Z11
Y11abs=abs(Y11)
Y11faze=atan(imag(Y11)/real(Y11))*180/pi
Z12=i*Xdc+i*Xvn+i*Xdc*i*Xvn/Zz
Y12=1/Z12
Y12abs=abs(Y12)
Y12faze=atan(imag(Y12)/real(Y12))*180/pi-180
