In [2]:

```
import math
v=10
r=4
#case a
i=v/float(r)
print "i=",format(i,'.1f'),"A"
#case b
#6ohm resistor is in series with 4 ohm resistor
i=v/(6+4)
v1=i*6
v2=i*4
print "voltage across 6 ohm resistor=",format(v1,'.1f'),"V"
print "voltage across 4 ohm resistor=",format(v2,'.1f'),"V"
#case c
i=10 #constant in both cases
v4=i*4
print "voltage when 4 ohm resistor is connected=",format(v4,'.1f'),"V"
v6=i*6
v=v4+v6
print "voltage when both resistors are in series=",format(v,'.1f'),"V"
```

In [1]:

```
import math
i=72
v=36
rs=v/float(i)
print "rs=",format(rs,'.1f'),"ohm"
print "the load voltage is expressed as 36rl/(0.5+rl)"
%matplotlib inline
import matplotlib.pyplot as plt
x=[40,50,60,72]
y=[36,34,32,30]
plt.plot(x,y)
plt.xlabel('il(A)')
plt.ylabel('vl(V)')
plt.show()
```

In [5]:

```
import math
v=24
r=0.75
ir=v/r
print "ir=",format(ir,'.1f'),"A"
il=v/(10+r) #since 10 is in series with r
print "il=",format(il,'.2f'),"A"
```

In [7]:

```
import math
vs=12
rs=0.3
il=10
#case a
p=vs*il
print "power=",format(p,'.1f'),"W"
#case b
power=il**2*rs
print "power dissipated=",format(power,'.1f'),"W"
#case c
totpow=(vs-il*rs)*il
print "total power supplied by practical source is=",format(totpow,'.1f'),"W"
i=vs/rs
print "current source=",format(i,'.1f'),"A"
```

In [8]:

```
import math
#case a
#v0/vs=r2/(r1+r2)=0.4r2=0.6r1
r1=10
r2=(0.6*r1)/float(0.4)
print "r2=",format(r2,'.1f'),"ohm"
#case b
#when r2 is parallel to r3
r3=200000
req=(r2*r3)/(r2+r3)
print "req=",format(req,'.1f'),"ohm"
#v0/vs=0.5825
change=(0.6-0.5825)/float(0.6)
print change
r3=20000
req=(r2*r3)/(r3+r2)
print "req=",format(req,'.1f'),"ohm"
#v0/vs=0.4615
change=(0.6-0.4615)/0.6
print change
```

In [12]:

```
import math
r=2
i=2
i3=3 #obtained by applying current divider rule to figure
i4=1
req=1/float(0.5+0.25+0.166) #1/2,1/4,1/6 values are converted to decimal form
print "req=",format(req,'.2f'),"ohm"
i2=(4*i4/float(6))
i1=(6*i2)/float(req)
#tracing circuit cabc via 6 ohm resistor and applying ohms law,
vs=i1*i4+i2*6
print "vs=",format(vs,'.2f'),"V"
```

In [13]:

```
import math
#combining series parallel series
#[(2+2+2)||(6+5+2)||10]+5
#[[6*6/6+6]+7]||10]+5=[10+10/10*10]+5=5+5=10
print "the value of series parallel resistances is 10 ohm"
```

In [20]:

```
import math
#case a
#rab=(80+40)||(60+40)
rab=(120*100)/float(120+100)
print "rab=",format(rab,'.2f'),"ohm"
#rab=(80||60)+(40||40)
rab=(4800/float(140))+(1600/80)
print "rab=",format(rab,'.3f'),"ohm"
#case b
#(60+80)||(40+40)
rcd=(140*80)/float(140+80)
print "rcd=",format(rcd,'.2f'),"ohm"
#(60||40)+(80||40)
rab=float(2400/float(100))+(3200/float(120))
print "rab=",format(rab,'.2f'),"ohm"
```

In [22]:

```
import math
#simplifying the circuit
ceq=1/float(0.333+0.666+0.2) #converted to decimal form
print "ceq=",format(ceq,'.8f'),"F"
```

In [29]:

```
import math
#case a
I=12/(2+((12*24)/float(36))) #values taken from circuit
I1=I*(24/float(36))
I2=I*(12/float(36))
print "i=",format(I,'1f'),"A"
print "i1=",format(I1,'1f'),"A"
print "i2=",format(I2,'1f'),"A"
#case b
power=(I**2)*2
print "power consumed by 2 ohm resistor=",format(power,'.2f'),"W"
power=(I1**2)*12
print "power consumed by 12 ohm resistor=",format(power,'.2f'),"W"
power=(I2**2)*24
print "power consumed by 2 ohm resistor=",format(power,'.2f'),"W"
#case c
v=I*2
print "voltage drop=",format(v,'.1f'),"V"
```

In [30]:

```
import math
#case a
#values taken and calculated from figure
r1=6
r2=12
r3=18
rab=3.21 #calculating similar to above using parallel in series resistances
print "rab=3.12ohm"
#case b
r4=30
r5=15
r6=30
ran=6 #similar as above
print "ran=6 ohm"
```

In [31]:

```
import math
#eqns derived from figure
#6v1-4v2=2-->1
#-4v1+7v2=-3-->2
#eqn 1 and 2 are written in matrix form and solved using cramers rule
print "v1=0.0769 V"
print "v2=-0.3846V"
print "current in 0.5ohm resistance is 0.154A,0.25ohm resistance is 1.846,0.66ohm resistor is -1.154A"
```

In [32]:

```
import math
#from the figure the eqns are written in matrix form and using cramers rule the value of v1 and v2 can be found
print "v1=3.6V"
print "v2=2.2V"
print "the current in 0.6 ohm resistor is 10.8A,0.2 ohm resistor is 7A,0.16ohm resistor is 13.2 A"
```

In [33]:

```
import math
#kcl is applied to the circuit and the eqns obtained are solved using cramer's rule
print "the voltages of nodes 1 and 3 are 50.29 and 57.71 respectively"
#i3=v/r
print "current through 16 ohm resistor is 1.64A"
```

In [34]:

```
import math
#the eqns obtained are converted to matrix form for solving using cramer's rule values are found
i1=5.224
i2=0.7463
i3=3.28
v=(i1-i3)*3
print "voltage across 3 ohm resistor is=",format(v,'.3f'),"V"
```

In [35]:

```
import math
#kvl eqns are obtained from figure which are solved to obtain currents
print "currents obtained are i1=2.013 and i2=1.273"
```

In [37]:

```
import math
#the currents are obtained by solving the eqns
i1=5.87
i2=-0.13
i3=-1.54
v=18-1.54*8
print "voltage at node D=",format(v,'.2f'),"v"
i=5.86/float(4)
print "current in 4 ohm resistor is=",format(i,'.2f'),"A"
power=18*1.54
print "power supplied by 18V source is=",format(power,'.2f'),"W"
```

In [38]:

```
import math
#node eqns are obtained form the figure
print "va=8.33V and vb=4.17V"
i=8.33/float(8)
print "current through 8 ohm resistor is=",format(i,'.2f'),"A"
```

In [39]:

```
import math
#eqns obtained are calculated just like above problems and are aolved for i1 and i2
print "i1=-1.363A and i2=-3.4A"
```

In [40]:

```
import math
#eqns are obtained from the figure and are solved for currents
i1=6.89
i2=3.89
i3=-2.12
i=2*(i2-i1)
print "current supplied by dependent source is=",format(i,'.1f'),"A"
power=6*i1
print "power supplied by voltage source is=",format(power,'.2f'),"W"
```

In [2]:

```
import math
#the following problem is based on usage of superposition theorem
i8=12/float(6+4+8) #current for 8 ohm resistor.the resistances are in series with each other.Hence 6+4+8
#next when voltage source is short circuited (8+4) total of resistance is obtained.The 4A is distributed in parallel branches as per current divider rule
i=(4*6)/float(6+12)
print "i8=",format(i8,'.3f'),"A"
print "i8'=",format(i,'.3f'),"A"
tot=i8+i
print "total current=",format(tot,'.1f'),"A"
```

In [8]:

```
import math
#kvl is applied to circuit
i=1
vth=12-(1*4) #12 is voltage 1 is current and 4 is resistance
rth=(4*5)/float(4+5)
i6=vth/float(rth+6) #since current passes through 6 ohm resistor
print i6,"A"
```

In [4]:

```
import math
#thevenin's theorem and superposition theorem used here
#applying mesh eqns to the 2 circuits and after getting the eqns they are solved using cramer's rule to obtain i1 and i2
i1=-0.6
i2=-1.2
#the value of currents indicates that they have assumed to be flowing in directions opposite to the assumed direction
vth=12-1.2*3 #voltage eqn
rth=1.425 #(1+2||12)||3=(1+(2*12)/(2+12))||3=19/7||3=19/7*3/19/7+3=1.425
i2=vth/(rth+2)
print "current through 2 ohm resistor is=",format(i2,'.2f'),"A"
print "Note that the same problem is again solved using superposition theorem and hence ignored "
```

In [5]:

```
import math
#using thevenin's theorem
#applying kcl at node a va is obtained
va=12
rth=1.33 #2||4
i5=vth/(rth+5)
print "current through 5 ohm resistor is=",format(i5,'.3f'),"A"
```

In [6]:

```
import math
#applying kvl to circuit
i=0.414
vth=12-4*0.414 #using vth formula
#when terminals a and b are short circuited applying kcl to node a gives isc=5*i
isc=2.07
rth=vth/isc
print "rth=",format(rth,'.3f'),"A"
```

In [7]:

```
import math
#norton's theorem
v=10
#applying kvl to closed circuit
isc=12/float(2+2)
rn=4 #resistance obtained by short circuiting v and opening i
iab=(4*3)/float(4+4) #current through 4 ohm connected across AB
print "iab=",format(iab,'.1f'),"A"
```

In [8]:

```
import math
#natural frequency needs to be determined
#req=[(6+6)||4]+[1||2]=3.6666
req=3.6667
l=4 #inductance
s=-req/float(l)
print "natural frequency=",format(s,'.5f'),"secinverse"
```

In [9]:

```
import math
#req=[10+2+(5||15)]=15.75
#case a
c=0.4
req=15.75
s=-1/float(c*req)
print "natural frequency=",format(s,'.5f'),"secinverse"
#case b
tc=req*0.4 #time constant
print "time constant=",format(tc,'.1f'),"sec"
```

In [11]:

```
import math
v=120
r=40
i=v/float(r)
#applying kvl to the closed loop
v=3*520
print "voltage=",format(v,'.1f'),"v"
#when v=120,R can be found by I*(r+20)=120-->r=20
r=20
print "r=20 ohm"
#when r=20 total r=20+20+20=60
r=60
l=10
tc=l/float(r) #time constant
print "tc=",format(tc,'.4f'),"sec"
#i=I0*e^-(t/tc)=3*e^(-6t)
energy=(10*9)/float(2)
benergy=0.05*energy
print "balance energy=",format(benergy,'.2f'),"J"
#(L*i^2)/2=2.25-->hence i=0.6708
#3*e^-6t=0.6708-->e^-6t=0.2236-->applying log on both sides we get t=0.25
print "t=0.25 sec"
```

In [12]:

```
import math
v=120
V=200
#v=V(1-e^-5/2R)
#120=200*(1-e^-5/2R)
#applying log on both sides and solving we get R=2.72 Mohm
print "R=2.72Mohm"
R=5
tc=10
#applying in the above eqn and solving lograthmically we get t=9.16
print "t=9.16 sec"
```

In [ ]:

```
```