##Network Theorem-1
##pg no.-2.4
##example2.1
print("\nConverting the two delta networks formed by resistors 4.5 Ohm, 3Ohm, and 7.5Ohm into equivalent star networks");
a=4.5;
b=3.;
c=7.5;
R1= (a*c)/(a+b+c);
R2= (c*b)/(c+b+a);
R3= (a*b)/(a+b+c);
print'%s %.2f %s %.2f %s %.2f %s '%("\nR1=R6 = ",R1," Ohm" and "\nR2=R5 =",R2," Ohm" and "\nR3=R4 =" ,R3," Ohm");
##Network Theorem-1
##pg no.-2.2
##example2.5
##converting delta network to star network
a=10.;
b=10.;
c=10.;
R=(a*b)/(a+b+c);
print("\nConverting the delta formed by three resistors of 10 Ohm into an equivalent star network");
print'%s %.2f %s'%("\nR1=R2=R3= ",R," Ohm");
##Network Theorem-1
##pg no.-2.7
##example2.3
a=4.;
b=3.;
c=6.;
##star to delta conversion
R1=c+a+((a*c)/b);
R2=c+b+((c*b)/a);
R3=a+b+((a*b)/c);
x=1.35;
y=0.9;
RAB=(c*(x+y))/(c+x+y);
print'%s %.2f %s'%("\nR1 = ",R1," Ohm");
print'%s %.2f %s'%("\nR2 = ",R2," Ohm");
print'%s %.2f %s'%("\nR3 = ",R3," Ohm");
print'%s %.2f %s'%("\nThe network can be simplified as, \nRAB = ",RAB," Ohm");
##Network Theorem-1
##pg no.-2.9
##example2.5
##converting delta network to star network
a=25.;
b=20.;
c=35.;
R1=(b*c)/(a+b+c);
R2=(a*b)/(a+b+c);
R3=(a*c)/(a+b+c);
print("\nConverting the delta formed by resistors 20 Ohm ,25 Ohm, 35 Ohm into an equivalent star network");
print'%s %.2f %s'%("\nR1= ",R1," Ohm");
print'%s %.2f %s'%("\nR2= ",R2," Ohm");
print'%s %.2f %s'%("\nR3= ",R3," Ohm");
##Network Theorem-1
##pg no.-2.15
##example2.8
a=5;
b=4;
c=3;
##Star to delta conversion
R1=a+b+((a*b)/c);
R2=c+b+((c*b)/a);
R3=a+c+((a*c)/b);
a1=6;
b1=4;
c1=8;
##Satr to delta conversion
R4=a1+b1+((a1*b1)/c1);
R5=c1+b1+((c1*b1)/a1);
R6=a1+c1+((a1*c1)/b1);
x=6.17;
y=9.78;
RAB=(x*y)/(x+y);
print("\nConverting star network formed by 3 Ohm,4 Ohm ,5 Ohm into equivalent delta network ");
print'%s %.2f %s %.2f %s %.2f %s'%("\nR1= ",R1," Ohm" and " \nR2= ",R2," Ohm" and " \nR3 = ",R3," Ohm");
print("\nSimilarly, converting star network formed by 6 Ohm,4 Ohm ,8 Ohm into equivalent delta network");
print'%s %.2f %s %.2f %s %.2f %s '%("\nR4= ",R4," Ohm" and " \nR5= ",R5," Ohm " and "\nR6 =",R6," Ohm");
print'%s %.2f %s'%("\n Simplifying the parallel networks, we get \nRAB = ",RAB," Ohms");
##Network Theorem 1
##page no-2.18
##example2.9
import math
import numpy
print("Applying KVL to mesh 1");
print("10*I1-3*I2-6*I3=0")##equation 1
print("Applying KVL to mesh 2");
print("-3*I1+10*I2=-5");##equation 2
print("Applying KVL to mesh 3");
print("-6*I1+10*I3=25");##equation 3
print("Solving the three equations");
A=numpy.matrix([[10, -3, -6],[-3 ,10 ,0],[-6, 0, 10]]) ##solving the equations in matrix form
B=numpy.matrix([[10], [-5], [25]])
X=numpy.dot(numpy.linalg.inv(A),B)
print[X];
print("I1=4.27 A");
print("I2=0.78 A");
print("I3=5.06 A");
print("I5ohm=4.27 A");
##Network Theorem 1
##page no-2.19
##example 2.10
import math
import numpy
from numpy import linalg
print("Applying KVL to mesh 1");
print("7*I1-I2=10")##equation 1
print("Applying KVL to mesh 2");
print("-I1+6*I2-3*I3=0");##equation 2
print("Applying KVL to mesh 3");
print("-3*I2+13*I3=-20");##equation 3
print("Solving the three equations");
A=numpy.matrix([[7 ,-1, 0],[-1, 6, -3],[0 ,-3, 13]]);##solving the equations in matrix form
B=numpy.matrix([[10], [0], [-20]])
X=numpy.dot(numpy.linalg.inv(A),B);
print[X];
print("I1=1.34 A");
print("I1=-0.62 A");
print("I3=-1.68 A");
print("I2ohm=1.34 A");
##Network Theorem 1
##page no-2.20
##example 2.11
import math
import numpy
print("Applying KVL to mesh 1");
print("3*I1-I2-2*I3=8");##equation 1
print("Applying KVL to mesh 2");
print("-I1+8*I2-3*I3=10");##equation 2
print("Applying KVL to mesh 3");
print("-2*I1-3*I2+10*I3=12");##equation 3
print("Solving the three equations");
A=numpy.matrix([[3 ,-1 ,-2],[-1, 8 ,-3],[-2 ,-3 ,10]]);##solving the equations in matrix form
B=numpy.matrix([[8], [10] ,[12]])
X=numpy.dot(numpy.linalg.inv(A),B);
print[X];
print("I1=6.01 A");
print("I1=3.27 A");
print("I3=3.38 A");
print("I5ohm=3.38 A");
##Network Theorem 1
##page no-2.21
##example 2.12
import numpy
print("Applying KVL to mesh 1");
print("8*I1-I2-4*I3=4");##equation 1
print("Applying KVL to mesh 2");
print("-I1+8*I2-5*I3=0");##equation 2
print("Applying KVL to mesh 3");
print("-4*I1-5*I2+15*I3=0");##equation 3
print("Solving the three equations");
A=numpy.matrix([[8 ,-1 ,-4],[-1 ,8 ,-5],[-4 ,-5 ,15]]);##solving the equations in matrix form
B=numpy.matrix([[4] ,[0], [0]])
X=numpy.dot(numpy.linalg.inv(A),B);
print[X];
print("I1=0.66");
print("I1=0.24 A");
print("I3=0.26 A");
print("current supplied by the battery = 0.66 A");
##Network Theorem 1
##page no-2.22
##example 2.13
import math
import numpy
print("Applying KVL to mesh 1");
print("V+13*I1-2*I2-5*I3=20");##mesh equation 1
print("Applying KVL to mesh 2");
print("2*I1-6*I2+I3=0");##mesh equation 2
print("Applying KVL to mesh 3");
print("V+5*I1+I2-10*I3=0");##mesh equation 3
print("putting I1=0 in equation 1, 2 and 3 we get");
print("V-2*I2-5*I3=20");##equation 1
print("-6*I2+I3=0");##equation 2
print("V+I2-10*I3=0");##equation 3
print("Solving the three equations");
A=numpy.matrix([[1 ,-2 ,-5],[0 ,-6 ,1],[1 ,1 ,-10]]);##solving the equations in matrix form
B=numpy.matrix([[20], [0] ,[0]])
X=numpy.dot(numpy.linalg.inv(A),B);
print[X];
print("V=43.7 V")
##Network Theorem 1
##page no-2.13
##example2.14
import math
import numpy
print("Mesh 1 contains a current source of 6A.Hence, we cannot write KVL equation for Mesh 1.direction of current source and mesh current I1 are same,");
print("I1=6A");##equation 1
print("Applying KVL to mesh 2");
print("18*I2-6*I3=108");##equation 2
print("Applying KVL to mesh 3");
print("6*I2-11*I3=9");##equation 3
print("Solving the three equations");
A=numpy.matrix([[18, -6],[6 ,-11]])##solving the equations in matrix form
B=numpy.matrix([[108] ,[9]])
X=numpy.dot(numpy.linalg.inv(A),B);
print[X];
print("I3 = 3A");
print("I2ohm = 3A");
##Network Theorem 1
##page no-2.23
##example2.15
print("from the fig,");
print("IA=I1");##equation 1
print("IB=I2");##equation 2
print("Applying Kvl to mesh 1:");
print("5-5*I1-10*IB-10*(I1-I2)-5*IA=0");
print("5-5*I1-10*I2-10*I1+10*I2-5*I1=0");
print("-20*I1=-5");
I1=5./20.;
print'%s %.2f %s'%("I1= ",I1," A");##equation 3
print("Applying Kvl to mesh 2:");
print("15*I1-15*I2=10");##equation 4
print("Put I1=0.25 A in equation 4");
print("-6.25=15*I2");
I2=-6.25/15.;
print'%s %.2f %s '%("I2= ",I2," A");
##Network Theorem 1
##page no-2.25
##example2.17
import math
import numpy
print("from the fig,");
print("V1=-5*I1");##equation 1
print("V2=2*I2");##equation 2
print("Applying Kvl to mesh 1:");
print("20*I1+3*I2=-5");##equation 3
print("Applying Kvl to mesh 2:");
print("11*I1-3*I2=10");##equation 4
print("Solving equations 3 and 4");##solving equations in matrix form
A=numpy.matrix([[20, 3],[11, -3]]);
B=numpy.matrix([[-5], [10]])
X=numpy.dot(numpy.linalg.inv(A),B);
print[X];
print("I1=0.161 A");
print("I2=-2.742 A");
##Network Theorem-1
##pg no.-2.25
##example2.18
import numpy
print("from the fig,");
print("Iy=I1");##equation 1
print("Ix=I1-I2");##equation 2
print("Applying Kvl to mesh 1:");
print("-10*I1+3*I2=5");##equation 3
print("Applying Kvl to mesh 2:");
print("-I1-3*I2=10");##equation 4
print("Solving equations 3 and 4");##solving equations in matrix form
A=numpy.matrix([[-10 ,3],[-1, -3]]);
B=numpy.matrix([[5] ,[10]])
X=numpy.dot(numpy.linalg.inv(A),B);
print[X];
print("I1=-1.364 A");
print("I2=-2878 A");
x=-1.364;
y=-2.878;
Ix=x-y;
print'%s %.2f %s %.2f %s '%("\nIy = ",x," A" and " \nIx = ",Ix," A");
##Network Theorem 1
##page no-2.26
##example2.19
import math
import numpy
print("Applying KVL to mesh 1:");
print("11*I1-10*I2=2");##equation 1
print("Writing current equation to supermesh:")
print("I3-I2=4");##equation 2
print("Applying KVL to outer path of supermesh:");
print("2*I1-3*I2-3*I3=0");##equation 3
print("solving these equations we get :");##solving equations in matrix form
A=numpy.matrix([[11, -10, 0],[0 ,-1 ,1],[2 ,-3, -3]]);
B=numpy.matrix([[2] ,[4] ,[0]])
X=numpy.dot(numpy.linalg.inv(A),B);
print[X];
I1=-2.35
I2=-2.78
I3=1.22
I4=I1-I2;
print'%s %.2f %s'%("\ncurrent through the 10 ohm resistor = I1-I2 = ",I4," A");
##Network Theorem 1
##page no-2.26
##example2.20
import math
import numpy
print("writing equation for supermesh,");
print("I1-I3=7");##equation 1
print("Applying Kvl to the outer path of the supermesh:");
print("-I1+4*I2-4*I3 = -7");##equation 2
print("Applying Kvl to mesh 2:");
print("I1-6*I2+3*I3 = 0");##equation 3
print("Solving equations 1 ,2 and 3");##solving equations in matrix form
A=numpy.matrix([[1 ,0 ,-1],[-1 ,4 ,-4],[1 ,-6 ,3]]);
B=numpy.matrix([[7], [-7], [0]])
X=numpy.dot(numpy.linalg.inv(A),B);
print[X];
print("I1=9 A");
print("I2=-2.5 A");
print("I3=-2 A");
x=2.5;
y=2;
z=x-y;
print'%s %.2f %s'%("\nCurrent through the 3-Ohm resistor = I2-I3 =",z," A");
##Network Theorem 1
##page no-2.27
##example2.21
import math
import numpy
print("Applying KVL to mesh 1:");
print("15*I1-10*I2-5*I3=50");##equation 1
print("Writing current equation to supermesh:")
print("I2-I3=2 A");##equation 2
print("Applying KVL to outer path of supermesh:");
print("-15*I1+12*I2+6*I3=0");##equation 3
print("solving these equations we get :");##solving equations in matrix form
A=numpy.matrix([[15, -10, -5],[0 ,1 ,-1],[-15, 12, 6]]);
B=numpy.matrix([[50] ,[2] ,[0]])
X=numpy.dot(numpy.linalg.inv(A),B);
print[X];
I1=20.
I2=17.33
I3=15.33
I4=I1-I3;
print'%s %.2f %s'%("\ncurrent through the 5 ohm resistor = I1-I3 = ",I4," A");
##Network Theorem 1
##page no-2.28
##example2.22
import math
import numpy
print("from the fig,");
print("I4=40");##equation 1
print("\nmeshes 2 and 3 form a supermesh. current equation for supermesh,")
print("-I1+2*I2-I3 = 0");##equation 2
print("Applying Kvl to supermesh:");
print("-1/5(I2-I1)-1/20*I2-1/15*I3-1/2(I3-I4)=0");##equation 3
print("applying KVL to mesh 1");
print("-1/10*I1-1/5(I1-I2)-1/6(I1-I4)=6");##equation 4
print("Solving equations 1 ,2 ,3 and 4");##solving equations in matrix form
A=numpy.matrix([[0 ,0 ,0 ,1],[-1, 2 ,-1 ,0],[0.2, -0.25, -17/30, 0.5],[-7/15, 0.2, 0 ,1/6]]);
B=numpy.matrix([[40], [0] ,[0], [6]])
X=numpy.dot(numpy.linalg.inv(A),B);
print[X];
print("I1=10 A");
print("I2=-20 A");
print("I3=30 A");
print("I4=40 A");
##Network Theorem 1
##page no-2.29
import numpy
##example2.24
print("Applying KCL to node 1:");
print("2*V1-V2 = 2");##equation 1
print("Applying KCL to node 2:");
print("3*V2-V1 = 4");##equation 2
print("Solving equations 1 and 2");##solving equations in matrix form
A=([[2 ,-1],[-1 ,3]]);
B=([[2] ,[4]])
X=numpy.dot(numpy.linalg.inv(A),B);
print[X];
print("V1= 2 V");
print("V2=-2 V");
##Network Theorem 1
##page no-2.30
##example2.25
import numpy
print("Applying KCL to node 1:");
print("8*VA-2*VB = 50");##equation 1
print("Applying KCL to node 2:");
print("-3*VA+9*VB = 85");##equation 2
print("Solving equations 1 and 2");##solving equations in matrix form
A=([[8 ,-2],[-3 ,9]]);
B=([[50], [85]])
X=numpy.dot(numpy.linalg.inv(A),B);
print[X];
print("VA= 9.39 V");
print("VB= 12.58 V");
##Network Theorem 1
##page no-2.30
import numpy
##example2.26
print("Applying KCL to node 1:");
print("5*V1-2*V2 = -24");##equation 1
print("Applying KCL to node 2:");
print("10*V1-31*V2+6*V3 = 300");##equation 2
print("Applying KCL to node 3:");
print("-4*V2 +9*V3 = 160");##equation 3
print("Solving equations 1,2 and 3");##solving equations in matrix form
A=([[5, -2 ,0],[10, -31, 6],[0, -4, 9]]);
B=([[-24] ,[300] ,[160]])
X=numpy.dot(numpy.linalg.inv(A),B);
print[X];
print("V1= -8.77 V");
print("V2= -9.92 V");
print("V3= 13.37 V");
x=13.37;
y=-9.92;
z=(x-y)/5.;
print'%s %.2f %s'%("\ncurrent through the 5 ohm resistor = V3-V2/5 = ",z," A");
##Network Theorem 1
##page no-2.31
##example2.27
import numpy
print("Applying KCL to node 1:");
print("50*V1-20*V2 = 2400");##equation 1
print("Applying KCL to node 2:");
print("-10*V1+19*V2 = 240");##equation 2
print("Solving equations 1 and 2");##solving equations in matrix form
A=([[50, -20],[-10, 19]]);
B=([[2400] ,[240]])
X=numpy.dot(numpy.linalg.inv(A),B);
print[X];
print("V1= 67.2 V");
print("V2=-48 V");
##Network Theorem 1
##page no-2.32
##example2.28
import numpy
print("Applying KCL to node 1:");
print("4*VA-2*VB = 5");##equation 1
print("Applying KCL to node 2:");
print("-2*VA+3*VB = 4");##equation 2
print("Solving equations 1 and 2");##solving equations in matrix form
A=([[4, -2],[-2 ,3]]);
B=([[5], [4]])
X=numpy.dot(numpy.linalg.inv(A),B);
print(X);
print("VA= 2.88 V");
print("VB= 3.25 V");
import numpy
##Network Theorem 1
##page no-2.33
##example2.29
print("Applying KCL to node 1:");
print("4*V1-2*V2-V3 = -24");##equation 1
print("Applying KCL to node 2:");
print("-50*V1+71*V2-20*V3 = 0");##equation 2
print("Applying KCL to node 3:");
print("-5V1-4*V2 +10*V3 = 180");##equation 3
print("Solving equations 1,2 and 3");##solving equations in matrix form
A=numpy.matrix([[4, -2, -1],[-50 ,71 ,-20],[-5, -4 ,10]]);
B=numpy.matrix([[-24], [0], [180]])
X=numpy.dot(numpy.linalg.inv(A),B);
print[X];
print("V1= 6.35 V");
print("V2= 11.76 V");
print("V3= 25.88 V");
x=25.88;
y=11.76;
z=(x-y);
print'%s %.2f %s'%("\ncurrent through the 5 ohm resistor = V3-V2/5 = ",z," A");
##Network Theorem 1
##page no-2.34
##example2.30
import numpy
print("Applying KCL to node 1:");
print("8*V1-V2 = 50");##equation 1
print("Applying KCL to node 2:");
print("-2*V1+11*V2 = -500");##equation 2
print("Solving equations 1 and 2");##solving equations in matrix form
A=([[8, -1],[-2, 17]]);
B=([[50] ,[-500]])
X=numpy.dot(numpy.linalg.inv(A),B);
print[X];
print("V1= 2.61 V");
print("V2=-29.1 V");
x=2.61;
y=-29.1;
I1=-x/2.;
I2=(x-y)/10.;##current through 10 Ohm resistor
I3=(y+50)/2.;##50 volts is the supply to the circuit
print'%s %.2f %s %.2f %s %.2f %s '%("\nI1= ",I1," A" and "\nI2= ",I2,"A" and " \nI3= ",I3," A");
##Network Theorem 1
##page no-2.34
##example2.31
import numpy
print("Applying KCL to node a:");
print("0.5*Va-0.2*Vb = 34.2");#equation 1
print("Applying KCL to node b:");
print("0.1*Va-0.4*Vb = -32.4");##equation 2
print("Solving equations 1 and 2");##solving equations in matrix form
A=numpy.matrix([[0.5,0.2],[0.1, -0.4]]);
B=numpy.matrix([[34.2], [-32.4]])
X=numpy.dot(numpy.linalg.inv(A),B);
print[X];
print("Va= 112 V");
print("Vb= 109 V");
x=112.;
y=109.;
I1=(120.-x)/0.2;
I2=(x-y)/0.3;
I3=(110-y)/0.1;
print'%s %.2f %s %.2f %s %.2f %s '%("\nI1=",I1," A " and "\nI2= ",I2," A" and " \nI3= ",I3," A");
##Network Theorem 1
##page no-2.35
##example2.35
import numpy
print("Applying KCL to node 1:");
print("V1 = 50");##equation 1
print("Applying KCL to node 2:");
print("-2*V1+17*V2 = 50");#equation 2
print("Solving equations 1 and 2");##solving equations in matrix form
A=([[1, 0],[-2, 17]]);
B=([[50] ,[50]])
X=numpy.dot(numpy.linalg.inv(A),B);
print[X];
print("V1= 50 V");
print("V2= 8.82 V");
x=8.82;
y=(x/10.);
print'%s %.2f %s'%("\ncurrent in the 10-Ohm resistor =V2/10 =",y," A");
##Network Theorem 1
##page no-2.36
##example2.33
import numpy
print("Applying KCL to node a:");
print("6*Va-5*Vb = -20");##equation 1
print("Applying KCL to node b:");
print("-10*Va+17*Vb-5*Vc = 0");##equation 2
print("At node c");
print("Vc = 20");
print("Solving equations 1,2 and 3");##solving equations in matrix form
A=numpy.matrix([[6 ,-5 ,0],[-10 ,17 ,-5],[0, 0, 1]]);
B=numpy.matrix([[-20], [0] ,[20]])
X=numpy.dot(numpy.linalg.inv(A),B);
print[X];
print("Va= 3.08 V");
print("Vb= 7.69 V");
x=3.08;
y=7.69;
z=20.;
Va = x-y;
Vb = y-z;
print'%s %.2f %s %.2f %s '%("\nV1 = Va-Vb = ",Va,"V" and "\nV2 = Vb-Vc = ",Vb," V");
##Network Theorem 1
##page no-2.37
##example2.334
import math
import numpy
print("At node A:");
print("VA = 60");##equation 1
print("Applying KCL to node B:");
print("-VA+3*VB-VC = 12");##equation 2
print("Applying KCL to node C:");
print("-2*VA-5*VB+10*VC");##equation 3
print("Solving equations 1,2 and 3");##solving equations in matrix
A=numpy.matrix([[1 ,0 ,0],[-1 ,3 ,-1],[-2 ,-5 ,10]]);
B=numpy.matrix([[60], [12], [24]])
X=numpy.dot(numpy.linalg.inv(A),B)
print[X];
print("VC= 31.68 V");
print("Voltage across the 100 Ohm resistor = 31.68 V");
##Network Theorem 1
##page no-2.38
##example2.35
import math
import numpy
print("Applying KCL to node 1:");
print("2.5*V1-0.5*V2 = 5");##equation 1
print("Applying KCL to node 2:");
print("V1-V2 = 0");##equation 2
print("Solving equations 1 and 2");##solving equations in matrix form
A=numpy.matrix([[2.5, -0.5],[1 ,-1]]);
B=numpy.matrix([[5] ,[0]])
X=numpy.dot(numpy.linalg.inv(A),B);
print[X];
print("V1= 2.5 V");
print("V2=-2.5 V");
##Network Theorem 1
##page no-2.39
##example2.37\
import math
import numpy
print("Applying KCL to node 1:");
print("2*V1+17*V2 = 0")##equation 1
print("Applying KCL to node 2:");
print("V1+6V2 = 0");##equation 2
print("Solving equations 1 and 2")##solving equations in matrix form
A=numpy.matrix([[2 ,17],[1, 6]]);
B=numpy.matrix([[0], [0]])
X=numpy.dot(numpy.linalg.inv(A),B)
print(X);
print("V1= 0 V");
print("V2= 0 V");
##Network Theorem 1
##page no-2.40
##example2.38
import numpy
import math
print("Applying KCL to node a:");
print("2*Va-0.5*Vb-0.5*Vc = 5");##equation 1
print("Applying KCL to node b:");
print("-3/2*Va+5/6*Vb+2/3*Vc = -1");##equation 2
print("Applying KCL to node c:");
print("1/2*Va+1/3*Vb-31/30*Vc = -1");##equation 3
print("Solving equations 1,2 and 3");##solving equations in matrix form
A=numpy.matrix([[2, -0.5, -0.5],[-3/2, 5/6, 2/3],[0.5 ,1/3 ,-31/30 ]]);
B=numpy.matrix([[5], [-1], [0]])
X=numpy.dot(numpy.linalg.inv(A),B)
print[X];
print("Va= 4.303 V");
print("Vb= 3.87 V");
print("Vc= 3.33 V");
##Network Theorem 1
##page no-2.41
##example2.39
import math
import numpy
print("from the figure");
print("V4= 40 V");##equation 1
print("nodes 2 and 3 form suoernode:");
print("V1-2*V2+V3 = 0");##equation 2
print("Applying KCL to node 1:");
print("7/15*V1-1/5*V2 = 2/3");##equation 3
print("Applying KCL to supernode :");
print("-23/30*V1 +83/60*V3 = 20");##equation 4
print("Solving equations 1,2,3 and 4");##solving equations in matrix form
A=numpy.matrix([[0, 0 ,0 ,1],[1 ,-2 ,1 ,0],[7/15 ,-1/5, 0, 0],[-23/30, 83/60, 0 ,0]]);
B=numpy.matrix([[40] ,[0], [2/3], [20]])
X=numpy.dot(numpy.linalg.inv(A),B)
print[X];
print("V1= 10 V");
print("V2= 20 V");
print("V3= 30 V");
##Network Theorem 1
##page no-2.42
##example2.40
import math
import numpy
print("selecting central node as reference node");
print("V1= -12 V");##equation 1
print("Applying KCL at node 1:");
print("-2*V1+2.5*V2-0.5V3 = 14");##equation 2
print("nodes 3 and 4 form a supernode");
print("0.2*V1+V3-1.2*V4 = 0");##equation 3
print("Applying KCL to supernode :");
print("0.1*V1-V2+0.5*V3+1.4*V4 = 0");##equation 4
print("Solving equations 1,2,3 and 4");##solving equations in matrix form
A=numpy.matrix([[1, 0, 0 ,0],[-2 ,2.5 ,-0.5 ,0],[0.2 ,0 ,1, -1.2],[0.1 ,-1 ,0.5, 1.4]]);
B=numpy.matrix([[-12], [14] ,[0],[0]])
X=numpy.dot(numpy.linalg.inv(A),B)
print[X];
print("V1= -12 V");
print("V2= -4 V");
print("V3= 0");
print("V4= -2 V");