CHAPTER02 : THE CIRCUIT ELEMENTS

Example E1 - Pg 27

In [7]:
#1a
V = 1.; #  voltage supply 
R = 10.; #  resistance in ohms 
I = V/R # current flowing through R
print '%s' %("a)")
print '%s %.f' %("voltage across the resistor (in volts)=",V)
print '%s %.2f' %("current flowing through the resistor (in amps) =",I)

#1b
V = 1.; #  voltage supply 
R1 = 10.; #  first resistance in ohms 
R2 = 5.; # resistance of the second resistor 
Vr1 = V * (R1/(R1 + R2)); # voltage across R1
Vr2 = V - Vr1; # voltage across R2
Ir = Vr1/R1; # current flowing through R
print '%s' %("b)")
print '%s %.2f' %("voltage across the first resistor (in volts)=",Vr1)
print '%s %.2f' %("voltage across the second resistor (in volts)=",Vr2)
print '%s %.2f' %("current flowing through the resistor (in amps) =",Ir)

#1c
# c - a
R1 = 10.; #  first resistance in ohms
R2 = 10.;
I = 1.; #  current source 
V = I*R1; #  voltage across R
print '%s' %("c - a)")
print '%s %.f' %("voltage across the resistor (in volts)=",V)
print '%s %.f' %("current flowing through the resistor (in amps) =",I)
# c - b
Vr1 = I*R1; #  voltage across R1
Vr2 = I*R2; # voltage across R2
Vr=Vr1+Vr2;
print '%s' %("c - b)")
print '%s %.f' %("voltage across the resistor (in volts)=",Vr)
print '%s %.f' %("current flowing through the resistor (in amps) =",I)
a)
voltage across the resistor (in volts)= 1
current flowing through the resistor (in amps) = 0.10
b)
voltage across the first resistor (in volts)= 0.67
voltage across the second resistor (in volts)= 0.33
current flowing through the resistor (in amps) = 0.07
c - a)
voltage across the resistor (in volts)= 10
current flowing through the resistor (in amps) = 1
c - b)
voltage across the resistor (in volts)= 20
current flowing through the resistor (in amps) = 1

Example E2 - Pg 35

In [8]:
R = 100.; #  resistance in ohms
I = 0.3; #  current in amps 
P = I**2 * R; #  power 
# power specification of the resistors available in the stock 
Pa = 5.;
Pb = 7.5;
Pc = 10.;

if Pa > P :
    print '%s' %("we should select resistor a")
if Pb > P :
    print '%s' %("we should select resistor b")
if Pc > P :
    print '%s' %("we should select resistor c")
we should select resistor c

Example E3 - Pg 35

In [9]:
L = 1.; # length of the copper wire in meters
A = 1. * 10.**-4.; #  cross sectional area of the wire in meter square 
rho = 1.724 * 10.**-8.; #  resistivity of copper in ohm meter
R = rho*L / A; #  resistance of the wire in ohm 

print '%s %.2e' %("resistance of the wire (in ohms)=",R) 
resistance of the wire (in ohms)= 1.72e-04

Example E4 - Pg 36

In [10]:
# 1 inches = 0.0254meters
# 1 foot = 0.3048 meters
import math 
d = 0.1*0.0254; #  diameter of the wire in meters
L = 10.*0.3048; # length of the wire in meters 
rho = 1.724*10.**-8.; #  resistivity of the wire in ohm-meter
A = math.pi*(d/2.)**2.; #  cross sectional area of the wire 
R = rho*L/A; # resistance of the wire in ohm 
print '%s %.2f' %("resistance of the wire (in ohm)=",R)
resistance of the wire (in ohm)= 0.01

Example E5 - Pg 41

In [11]:
%matplotlib inline
import math
import numpy as np
from matplotlib import pyplot
L = 0.1; #  inductance of the coil in henry 
t1= np.linspace(0,0.1, num=101)
t2= np.linspace(0.101,0.3, num=201)
t3= np.linspace(0.301,0.6,num=301)
t4= np.linspace(0.601,0.7,num=101)
t5= np.linspace(0.701,0.9,num=201)
# current variation as a function of time 
i1 = 100.*t1;
i2 = (-50.*t2) + 15.;
i3 = np.zeros(301)
for i in range(0,301):
	i3[i] = -100.*math.sin(math.pi*(t3[i]-0.3)/0.3);

i4 = (100.*t4) - 60.;
i5 = (-50.*t5) + 45.;

t = ([t1,t2,t3,t4,t5]);
i = ([i1,i2,i3,i4,i5]);
pyplot.plot(t1, i1);
pyplot.plot(t2, i2);
pyplot.plot(t3, i3);
pyplot.plot(t4, i4);
pyplot.plot(t5, i5);

dt = 0.001;
di1 = np.diff(i1);
di2 = np.diff(i2);
di3 = np.diff(i3);
di4 = np.diff(i4);
di5 = np.diff(i5);
V1 =np.array((L/dt)*di1); # voltage drop appearing across the inductor terminals
V2 =np.array((L/dt)*di2); # voltage drop appearing across the inductor terminals
V3 =np.array((L/dt)*di3); # voltage drop appearing across the inductor terminals
V4 = np.array((L/dt)*di4); # voltage drop appearing across the inductor terminals
V5 = np.array((L/dt)*di5); # voltage drop appearing across the inductor terminals
print(V2)
Tv = np.linspace(0,0.899,num=900);
V = []
V.extend(V1)
V.extend(V2)
V.extend(V3)
V.extend(V4)
V.extend(V5)
print(len(V))
pyplot.plot(Tv, V)
pyplot.show();
[-4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975
 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975
 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975
 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975
 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975
 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975
 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975
 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975
 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975
 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975
 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975
 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975
 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975
 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975
 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975
 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975
 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975
 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975
 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975
 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975 -4.975]
900

Example E7 - Pg 60

In [12]:
# a
Ri = 1.; 
Rf = 39.;
A = 10.**5.; # open loop gain of the op-amp
G = A/(1. + (A*Ri/(Ri+Rf))); # actual voltage gain of the circuit 
print '%s' %("a")
print '%s %.2f' %("actual voltage of the circuit =",G)

# b
G1 = 1 + (Rf/Ri); #  voltage gain of the circuit with infinite open loop gain
print '%s' %("b")
print '%s %.f' %("for ideal case the voltage gain =",G1)

# c
er = ((G1 - G)/G)*100.; # percent error 
print '%s' %("c")
print '%s %.2f' %("percent error of the ideal value compared to the actual value=",er)
a
actual voltage of the circuit = 39.98
b
for ideal case the voltage gain = 40
c
percent error of the ideal value compared to the actual value= 0.04

Example E8 - Pg 61

In [15]:
G = 4.; #  voltage gain of the circuit 
r = G -1.; #  ratio of the resistances in the non-inverting op-amp circuit
print '%s %.2f' %("Rf/Ri =",r)
# Result:
# A suitable choice for R1 is 10K, Hence Rf = 30K
Rf/Ri = 3.00

Example E9 - Pg 61

In [14]:
G = 4.;
r = G; #  ratio of the resistances in the inverting op-amp circuit
print '%s %.f' %("Rf/Ri",r)
# Result;
# A suitable choice for Rf=30K and R1=7.5K
# therefore input resistance R1 = 7.5K
Rf/Ri 4