% this program computes the current
% flowing in the resistor RB and power supplied by source
% it computes the loop currents, when the impedance
% matrix Z and voltage vector U are given
% Z is the impedance matrix
% U is the voltage matrix
% initialize the matrix Z and vector U
Z = [40 -10 -30;
    -10  30  -5;
    -30  -5  65];
U = [10; 0; 0];
% solution for the loop currents
I = inv(Z)*U;
% the current through RB is calculated
IRB = I(3)-I(2);
disp(['The current through the resistor RB is ',num2str(IRB),' A.'])
% the power supplied by source is calculated
P = 10*I(1);
disp(['The power supplied by voltage source is ',num2str(P),' W.'])
