clear all

Vt=230*exp(j*17*pi/180);
Vr=Vt*exp(-j*120*pi/180);
Vs=Vt*exp(j*120*pi/180);

printf("Vr = %g /_ %g V, Vs = %g /_ %g V, Vt = %g /_ %g V\n",
       abs(Vr), angle(Vr)*180/pi, abs(Vs), angle(Vs)*180/pi, abs(Vt),
       angle(Vt)*180/pi)

ZA=20+j*15; ZB=15+j*10; ZC=10-j*18; Z1=1+j*4; Z2=1+j*4; Z3=2+j*3;
Von = (Vr/(Z1+ZA)+Vs/(Z2+ZB)+Vt/(Z3+ZC))/(1/(Z1+ZA)+1/(Z2+ZB)+1/(Z3+ZC))
printf("Von =  %g /_ %g V \n", abs(Von), angle(Von)*180/pi)

Ir = (Vr-Von)/(Z1+ZA);
Is = (Vs-Von)/(Z2+ZB);
It = (Vt-Von)/(Z3+ZC);

printf("Ir = %g /_ %g A, Is = %g /_ %g A, It = %g /_ %g A\n",
       abs(Ir), angle(Ir)*180/pi, abs(Is), angle(Is)*180/pi, abs(It),
       angle(It)*180/pi)

A = [Z1+ZA+Z2+ZB -(Z2+ZB); -(Z2+ZB) Z2+ZB+Z3+ZC];
b = [-Vs+Vr; -Vt+Vs];
I = inv(A)*b;
printf("I1 = %g /_ %g A, I2 = %g /_ %g A\n", abs(I(1)), angle(I(1))*180/pi,
       abs(I(2)), angle(I(2))*180/pi)
ir = I(1);
is = I(2)-I(1);
it = -I(2);
printf("Ir = %g /_ %g A, Is = %g /_ %g A, It = %g /_ %g A\n",
       abs(ir), angle(ir)*180/pi, abs(is), angle(is)*180/pi, abs(it),
       angle(it)*180/pi)

Va = Ir*ZA; Vb = Is*ZB; Vc = It*ZC;
printf("Va = %g /_ %g V, Vb = %g /_ %g V, Vc = %g /_ %g V\n",
       abs(Va), angle(Va)*180/pi, abs(Vb), angle(Vb)*180/pi, abs(Vc),
       angle(Vc)*180/pi)

S = Va*conj(Ir) + Vb*conj(Is) + Vc*conj(It)

Wa = real(Va*conj(Ir))
Wb = real(Vb*conj(Is))
Wc = real(Vc*conj(It))
W3 = Wa+Wb+Wc

W1 = real((Va-Vb)*conj(Ir))
W2 = real((Vc-Vb)*conj(It))
WW = W1+W2

pf = real(S)/abs(S) 
