Chapter 1 : Introduction

Pg: 45 Ex: 1.1

In [3]:
%matplotlib inline
from matplotlib.pyplot import plot,show,subplot,title,xlabel,ylabel
from numpy import arange,exp
#As both q and i are 0 when t<0, graph coincides with x-axis till t=0 and we here,show the part where t>0
t=arange(0,0.04+0.000001,0.000001)
q=[];i=[]
for time in t:
    q.append(2*(1-exp(-100*time)))
    #current i=dq/dt=200*e**(-100*t)
    i.append(200*exp(-100*time))
subplot(121)
title('charge vs time')
xlabel('time in ms')
ylabel('charge in coulombs')
#ms-milli second(10**-3)
plot(t*10**3,q)
subplot(122)
title('current vs time')
xlabel('time in ms')
ylabel('current in amperes')      #ms-milli second(10**-3)
plot(t*10**3,i)
show()

Pg: 46 Ex: 1.2

In [5]:
#element A
print 'ELEMENT A :'
V_a=12#
i_a=2#
P_a=V_a*i_a#      #passive reference configuration (current enters through +ve polarity)
if(P_a>0):      #absorption of power
    print 'Power for element A in watts is',P_a
    print 'As a battery, element A is being charged'
elif(P_a<0) :       #supplying of power
    print 'Power for element A in watts is',P_a
    print 'As a battery, element A is being discharged'


#element B
print 'ELEMENT B'
V_b=12#
i_b=1#
P_b=-V_b*i_b#      #opposite to passive reference configuration (current enters through -ve polarity)
if(P_b>0):       #absorption of power
    print 'Power for element B in watts is',P_b
    print 'As a battery, element B is being charged'
elif(P_b<0) :       #supplying of power
    print 'Power for element B in watts is',P_b
    print 'As a battery, element B is being discharged'


#element C
print 'ELEMENT C'
V_c=12#
i_c=-3#
P_c=V_c*i_c#      #passive reference configuration (current enters through +ve polarity)
if(P_c>0):       #absorption of power
    print 'Power for element C in watts is',P_c
    print 'As a battery, element C is being charged'
elif(P_c<0):      #supplying of power
    print 'Power for element C in watts is',P_c
    print 'As a battery, element C is being discharged'
ELEMENT A :
Power for element A in watts is 24
As a battery, element A is being charged
ELEMENT B
Power for element B in watts is -12
As a battery, element B is being discharged
ELEMENT C
Power for element C in watts is -36
As a battery, element C is being discharged

Pg: 47 Ex: 1.3

In [6]:
# initialisation of variables
G= 9200 # N/m**2
g1= 9.81 # m/sec**2
g2= 9.805 #m/sec**2
# Calculations
rho= G/g1
G2= rho*g2
# Results
print 'Density of Fluid = %.1f N sec**2/m**4'%(rho)
print '\n New Specific Weight = %.f N/m**3'%(G2)
Density of Fluid = 937.8 N sec**2/m**4

 New Specific Weight = 9195 N/m**3

Pg: 47 Ex: 1.4

In [9]:
from numpy import pi
d=2.05*10**-3#      #diameter of wire
l=10#      #length of wire
P=1.72*10**-8#      #resistivity of copper
A=pi*d**2/4#      #area of wire
R=P*l/A#      #resistance of the copper wire
print " All the values in the textbook are approximated, hence the values in this code differ from those of textbook"
print 'Resistance of copper wire = %0.2f ohms'%R
 All the values in the textbook are approximated, hence the values in this code differ from those of textbook
Resistance of copper wire = 0.05 ohms

Pg: 47 Ex: 1.5

In [10]:
P=1500#      #power of heater
V=120#      #operating voltage
R=V**2/P#      #resistance of heater element
i=V/R#      #operating current
print 'resistance of heater element = %0.2f ohms'%R
print 'operating current = %0.2f amperes'%i
resistance of heater element = 9.00 ohms
operating current = 13.00 amperes

Pg: 48 Ex: 1.6

In [11]:
V_s=10#      #source voltage
R=5#
V_x=-V_s#      #Voltage across R(applying KVL)
#the actual polarity is opposite to the reference, so we take polarity to be +ve at the top end of resistance
i_x=-V_x/R#      #ohm's law(-ve sign as V_x and i_x have references opposite to passive configuration)
i_y=-i_x#      #current through source
P_s=V_s*i_y#      #power for voltage source
P_R=-V_x*i_x#      #power for resistance(-ve sign as V_x and i_x have references opposite to passive configuration)
print 'voltage across resistance = %0.2f volts'%V_x
print 'current through resistance = %0.2f amperes'%i_x
print 'current through source = %0.2f amperes'%i_y
print 'power for voltage source = %0.2f watts'%P_s
print 'power for resistance = %0.2f watts'%P_R
if(V_x==-10 and i_x==2 and i_y==-2 and P_s==-20 and P_R==20):
    print 'Results are in agreement with those previously found in the textbook'
voltage across resistance = -10.00 volts
current through resistance = 2.00 amperes
current through source = -2.00 amperes
power for voltage source = -20.00 watts
power for resistance = 20.00 watts
Results are in agreement with those previously found in the textbook

Pg: 48 Ex: 1.7

In [12]:
R_1=10#
R_2=5#
V_R_2=15#      #voltage across R_2
a=0.5#
i_y=V_R_2/R_2#      #current across R_2
i_x=i_y*2/3#      #current across R_1, by applying KCL at the top end of the controlled source 
V_x=i_x*R_1#      #ohm's law
V_s=V_x+V_R_2#      #KVL around the periphery of the circuit
print 'Source voltage for given circuit = %0.2f volts'%V_s
Source voltage for given circuit = 35.00 volts