clear; clc
% input values
% the impedances are in ohms
Z1=50; Z2=-j*50; Z3=-j*50; Z4=j*100; Z5=j*100; Z6=50;
% the voltages are in volts
% voltage u01:
u01max=10; u01angle=0; % angle in degrees
% complex representation of the voltage u01
U01=u01max*exp(j*u01angle*pi/180);
% incidence matrix B
B=[1  1  0  0  1  0;
   0 -1 -1  1  0  0;
   0  0  1  0 -1  1];
% column matrix U0
U0=[U01; 0; 0; 0; 0; 0];
% diagonal matrix Z
Z=diag([Z1 Z2 Z3 Z4 Z5 Z6]);
U0s=B*U0;
Zs=B*Z*B';
Is=inv(Zs)*U0s;
I=B'*Is
Zin=U01/I(1)-Z1
U6=I(6)*Z6
Ku=U6/U01