clc
% Vstupni parametry
delka=100
Rp1=0.14
Lp1=1.24E-3
Cp1=15.5E-9
Gp1=50E-9
frekv=50
omega=2*pi*frekv
Un=110
Unf=Un/sqrt(3)
P2=80

% Odvozene parametry
Rp=Rp1*delka
Xp=Lp1*omega*delka
Bp=Cp1*omega*delka
Gp=Gp1*delka
Zl=Rp+j*Xp
Yg=Gp+j*Bp
Zvl=sqrt(Zl/Yg)
Zvlabs=abs(Zvl)
% Hodnota orientacni
Zvlabs2=sqrt(Lp1/Cp1)
gama=sqrt(Zl*Yg/delka^2)
alfa=real(gama)
beta=imag(gama)
gamaabs=abs(gama)
gamaangle=angle(gama)/pi*180
Spr=Un^2/Zvl
Ppr=real(Spr)
Ppr=Un^2/Zvlabs
Ppr=Un^2/Zvlabs2

% Koncove parametry
U2=Unf
P2=80
CosFi=1
I2=P2/sqrt(3)/Un/CosFi

%T-clanek
U=U2+1/2*Zl*I2
I=Yg*U
I1=I2+I
U1=U+1/2*Zl*I1

U1=(1+Zl*Yg/2)*U2+Zl*(1+Zl*Yg/4)*I2
I1=Yg*U2+(1+Zl*Yg/2)*I2

VelSipky=0.03;
clf;
hold on;
zobrazfazor(0,  U1, 'r', VelSipky, 1)
zobrazfazor(0,  U2, 'b', VelSipky, 1)
zobrazfazor(U2, 1/2*Zl*I2, 'k', VelSipky, 0)
zobrazfazor(U,  1/2*Zl*I1, 'k', VelSipky, 0)
zobrazfazor(0,  U,  'g', VelSipky, 1)
hold off;
axis('equal')
grid on;

pause

%Pi-clanek
Ic=1/2*Yg*U2
I=I2+Ic
U1=U2+Zl*I
Icc=1/2*Yg*U1
I1=I2+Ic+Icc

U1=(1+Zl*Yg/2)*U2+Zl*I2
I1=Yg*(1+Zl*Yg/4)*U2+(1+Zl*Yg/2)*I2

VelSipky=0.03;
clf;
hold on;
zobrazfazor(0,  U1, 'r', VelSipky, 1)
zobrazfazor(0,  U2, 'b', VelSipky, 1)
zobrazfazor(U2, Zl*I, 'k', VelSipky, 0)
hold off;
axis('equal')
grid on;

pause

VelSipky=0.03;
clf;
hold on;
zobrazfazor(0, I1, 'r', VelSipky, 1)
zobrazfazor(0, I2, 'b', VelSipky, 1)
zobrazfazor(I2,  Ic, 'k', VelSipky, 0)
zobrazfazor(I2+Ic, Icc, 'k', VelSipky, 0)
hold off;
axis('equal')
grid on;

% Ubytek velikosti napeti
dU=(abs(U1)-abs(U2))/Unf*100
% priblizne vztahy
dU2=Rp*abs(I2)*CosFi/Unf*100
dU3=Rp*P2/Un^2*100
dU4=(Rp*abs(I2)*CosFi + Xp*abs(I2)*sin(acos(CosFi)))/Unf*100

% Cinne a jalove ztraty
S1=3*U1*conj(I1)
S2=3*U2*conj(I2)
P1=real(S1)
P2=real(S2)
Q1=imag(S1)
Q2=imag(S2)
dPproc=(P1-P2)/P1*100
dQproc=(Q1-Q2)/Q1*100
% priblizne vztahy
dP2=3*Rp*abs(I2)^2
dP3=3*Rp*abs(I1)^2
dP4=3*(Rp*abs(I2)^2 + abs(U2)^2*Gp)
dP5=3*(Rp*abs(I1)^2 + abs(U1)^2*Gp)
dQ2=3*Xp*abs(I2)^2
dQ3=3*Xp*abs(I1)^2
dQ4=3*(Xp*abs(I2)^2 - abs(U2)^2*Bp)
dQ5=3*(Xp*abs(I1)^2 - abs(U1)^2*Bp)
