%matplotlib inline
import math
from numpy import cos,sin,arange
from matplotlib.pyplot import plot,suptitle,xlabel,ylabel
#Example 7.1")
t1 = arange(-5,8+0.5,0.5)
v1 = cos (t1)
# Calculation and Results
plot(t1,v1)
suptitle ('v1 vs t1')
xlabel('t1')
ylabel('v1 ');
#From the graph
print "Time period1 = %3.3fs Frequency 1 = %0.3fHz"%(6.2832,0.159)
t2 = arange(-4,10+0.5,0.5)
v2 = sin (t2)
plot(t2,v2)
suptitle ('v2 vs t2')
xlabel('t2')
ylabel('v2 ');
#From the graph
print "Time period 2 = %3.3fs Frequency 2 = %0.3fHz"%(6.2832,0.159)
t3 = arange(-1,1.5+0.05,0.05)
v3 = 2* cos (2*math.pi*t3)
plot(t3,v3)
suptitle ('v3 vs t3')
xlabel('t3')
ylabel('v3 ');
#From the graph
print "Time period 3 = %ds Frequency 3 = %dHz"%(1,1)
t4 = arange(-5,12+0.5,0.5)
v4 = 2*cos (math.pi*t4/4-math.pi/4)
plot(t4,v4)
suptitle ('v4 vs t4')
xlabel('t4')
ylabel('v4 ');
#From the graph
print "Time period 4 = %ds Frequency 4 = %0.3fHz"%(8,0.125)
t5 = arange(-1,1+0.005,0.005)
v5 = 5*cos (10*t5+math.pi/3)
plot(t5,v5)
suptitle ('v5 vs t5')
xlabel('t5')
ylabel('v5 ');
#From the graph
print "Time period 5 = %0.3fs Frequency 5 = %3.2fHz"%(.62832,1.59)
%matplotlib inline
import math
from numpy import cos,arange
from matplotlib.pyplot import plot,suptitle,xlabel,ylabel
#Example 7.2")
# Input
#Let wt = q
q = arange(-8,8+0.5,0.5)
# Calculation
v = 5*cos (q)
# Results
plot(q,v)
suptitle ('v vs wt')
xlabel('wt')
ylabel('v ');
%matplotlib inline
import math
from numpy import cos,arange
from matplotlib.pyplot import plot,suptitle,xlabel,ylabel
#Example 7.3")
# Input
t1 = arange(-10,10+0.05,0.05)
# Calculation
v = 5*cos (math.pi*t1/6+math.pi/6)
# Results
plot(t1,v)
suptitle ('v vs math.pi*t/6')
xlabel('math.pi*t/6')
ylabel('v ');
import math
#Example 7.5")
# Given
#v(t) = math.cos5t+3math.sin(3t+45)")
#Finding the periods of individual terms
#Period of math.cos5t = 2*math.pi/5")
#Period of 3*math.sin(3t+45) = 2*math.pi/3")
#If T = 2*math.pi
T = 2*math.pi;
#Now T = 5*T1 = 3*T2")
#Now the relation for T is the smallest common integral multiple of T1 and T2
print "Period = %3.2fs"%(T)
import math
from scipy.integrate import quad
#Example 7.13")
# Given
#capacitance is 1uF")
C = 1*10**-6;
#a)")
#Let k = 1 which results in t = 5ms
t = 5*10**-3;
def f2(t):
return .004
vac = quad(f2,0,0.003)[0]
print "vac = %dV"%(vac);
#In general
#At t = 5k voltage follows as v = 8k ms")
#b)")
#As vdc = 1/C*integrate(Idc*dt)
#On solving for Idc
vdc = vac
def f3(t):
return 1./vac
Idc = (1/( quad(f3,0,0.005)[0]/C))
print "Idc = %3.2fmA"%(Idc);
#Idc is equal to <i(t)> in the period of 5ms")
import math
#Example 7.17")
# Given
#capacitance is 100nF")
#The voltage across capacitor increases linearly from 0 to 10V")
C = 100*10**-9;
#From figure 7.10(a)
#a)")
#At t = T voltage across capacitor = 10V
vc = 10;
Q = C*vc;
print "Charge across capacitor is %fC"%(Q)
#b)")
#The waveform shown in fig 7.10(a) can be written as
#0 t<0")
#I0 = 10**-6/T 0<t<T")
#0 t>T")
#For T = 1s;
T = 1.;
I0 = 10**-6/T;
print "I01s) = %fA"%(I0);
#For T = 1ms;
T = 1.*10**-3;
I0 = 10**-6/T;
print "I01ms) = %0.3fA"%(I0);
#For T = 1us;
T = 1.*10**-6;
I0 = 10**-6/T;
print "I01us) = %dA"%(I0);
%matplotlib inline
import math
from numpy import cos,arange,exp
from matplotlib.pyplot import plot,suptitle,xlabel,ylabel
#Example 7.22")
#The general equation of exponential decay function is given by
#v(t) = A*e(-t/T)+B")
#We need to solve A and B
#At t = 0 we get v(0) = A+B (1)
#at t = inf we get B = 1 (2)
#Solving (1) and (2)
A = 4;
B = 1;
T = 3;
t = arange(0,10+0.05,0.05)
v = 4*exp(-t/T)+1;
# Results
plot(t,v)
suptitle ('v vs t')
xlabel('t')
ylabel('v');
%matplotlib inline
import math
from numpy import cos,arange,exp
from matplotlib.pyplot import plot,suptitle,xlabel,ylabel
#Example 7.23")
#Sketch voltage 'v'
t = arange(-.001,0.00005,0.00005)
t1 = arange(0,0.001+0.00005,0.00005)
T = 1.*10**-3;
V0 = 10.;
v = V0*exp(t/T)
v1 = V0*exp(-t1/T)
# Results
plot(t,v)
plot(t1,v1)
suptitle ('v vs t')
xlabel('t (ms)')
ylabel('v ');
#Sketch current 'i'
t = arange(-.001,0.00005,0.00005)
t1 = arange(0,0.001+0.00005,0.00005)
T = 1.*10**-3;
I0 = 10.*10**-3;
i = I0*exp(t/T)
i1 = -I0*exp(-t1/T)
plot(t,i)
plot(t1,i1)
suptitle ('i vs wt')
xlabel('t (ms)')
ylabel('i (mA)');
import math
#Example 7.25")
Xavg = (2+4+11+5+7+6+9+10+3+6+8+4+1+3+5+12)/16.;
#Let X = X**2eff
X = (2**2+4**2+11**2+5**2+7**2+6**2+9**2+10**2+3**2+6**2+8**2+4**2+1**2+3**2+5**2+12**2)/16.
Xeff = math.sqrt(X);
# Results
print "Xavg = %d Xeff = %3.2f"%(Xavg,Xeff)
import math
# Given
#Period = 10s")
#Interval is 1ms")
#Voltage of binary signal is either 0.5 or -0.5")
T = 10;
#During 10s period there are 10000 intervals of 1ms each
#For calculating average equal number of intervals are considered at 0.5V and -0.5V
vavg = (0.5*5000-0.5*5000)/10000.
#The effective value of v(t) is
#Let V = V**2eff
V = (0.5**2*5000+(-0.5)**2*5000)/10000.
# Calculation
Veff = math.sqrt(V)
# Results
print "vavg = %dV Veff = %3.2fV"%(vavg,Veff)