MP Assignment 3
MP Assignment 3
(a) Find charge on the capacitor after every 0.1 ms and display the data on the python console as data
frame. Take time range [0 : 7 ms]
(b) From the given data frame, determine the time constant(time duration after which the charge on the
capacitor falls to q0/e) of the given RC circuit. (c) Plot the variation of charge on capacitor as function of
time.
INPUT:
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
C = 10**(-6)
R = 1000
qo = 1*10**(-6)
t = np.arange(0,7+0.1,0.1)
q = qo*np.exp(-t/(1000*R*C))
z = {'Charge' :q, 'Time' :t}
df = pd.DataFrame(z)
tc = R*C
print(tc)
print(df)
plt.plot(t,q)
plt.grid()
plt.xlabel('Time')
plt.ylabel('Charge')
plt.title('Discharge of Capacitor')
plt.text(3, 0.6*10**(-6), '''Ronak Raj Sharma-877''')
OUTPUT:
runfile('C:/Users/shaya/Assignment 3/Q1.py', wdir='C:/Users/shaya/Assignment 3')
0.001
Charge Time
0 1.000000e-06 0.0
1 9.048374e-07 0.1
2 8.187308e-07 0.2
3 7.408182e-07 0.3
4 6.703200e-07 0.4
.. ... ...
66 1.360368e-09 6.6
67 1.230912e-09 6.7
68 1.113775e-09 6.8
69 1.007785e-09 6.9
70 9.118820e-10 7.0
INPUT:
import numpy as np
import pandas as pd
No = 1000
ld = 1
t = np.arange(0,5+0.02,0.02)
N = No*np.exp(-ld*t)
df = pd.DataFrame(z)
print(df)
plt.plot(t, N)
plt.grid()
plt.ylabel('Nucleons')
plt.xlabel('Time')
OUTPUT:
Nucleons Time
0 1000.000000 0.00
1 980.198673 0.02
2 960.789439 0.04
3 941.764534 0.06
4 923.116346 0.08
.. ... ...
3. Single Slit Diffraction: When LASER light falls on a single slit, diffraction phenomenon produces a fringe
pattern on the screen with peak brightness Io at the center. Intensity distribution as a function of
diffraction angle can be described by the equation
I(α) = I0 (sinα/α)2
(a) Vary angle α in range [-10 radian :10 radian] in step of 0.1 radian and plot the
(b) Vary angle α in range [-10 radian :10 radian] in step of 0.09 radian and plot the
variation of I vs α. Take I0 = 1.
INPUT:
import math as M
I1=[]
alpha1=[]
q=1
for i in range(-100,101,1):
alpha=i/10
if alpha==0:
else:
pass
alpha1.append(alpha)
I=q*(M.sin(alpha)/(alpha))**2
I1.append(I)
plt.plot(I1,alpha1,color='g')
plt.xlabel("Intensity")
plt.ylabel("angle")
plt.grid()
plt.title("plot of I vs alpha")
OUTPUT:
b) INPUT:
import numpy as np
import pandas as pd
Io = 1
alpha = np.arange(-10,10,0.09)
I = Io*(np.sin(alpha)/alpha)**2
z = {'Intensity' :I, 'alpha' :alpha}
df = pd.DataFrame(z)
print(df)
plt.plot(alpha, I)
plt.grid()
plt.ylabel('Intensity')
plt.xlabel('Alpha')
OUPUT:
Intensity alpha
0 0.002960 -10.00
1 0.002215 -9.91
2 0.001537 -9.82
3 0.000954 -9.73
4 0.000491 -9.64
.. ... ...
(a) Plot the variation of current Irms as a function of ω(rad/s). Vary ω from [500 rad/s : 40,000 rad/s] in
step of 500 rad/s.
(b) Plot the variation of capacitive reactance and inductive reactance as a function of ω in a single graph
(using the same ω axis) .
(d) Plot above three graphs (of part (a), (b) & (c)) in a single graphic window as separate plots using
subplot.
(e) Create dataframe which display ω, Irms, XL, XC, R & Z. Display data frame on the console.
(f) Use the given data frame to find value of ω called the Resonant Frequency for which impedance is
minimum and current is maximum.
INPUT:
import math as M
import pandas as pd
def LCR():
C=10**(-6)
L=10**(-2)
R=100
V=5
w1=[]
Z1=[]
I1=[]
Xl1=[]
Xc1=[]
for w in range(500,40000+500,500):
w1.append(w)
Xl=w*L
Xl1.append(Xl)
Xc=1/(w*C)
Xc1.append(Xc)
Z=M.sqrt((Xl-Xc)**2+(R)**2)
Z1.append(Z)
I=V/Z
I1.append(I)
return(w1,I1,Xl1,Xc1,Z1,R)
p,q,r,s,t,u=LCR()
if a==1:
plt.plot(p,q,color='g')
plt.xlabel("w(in rad/s)")
plt.ylabel("Irms")
plt.grid()
if a==2:
plt.plot(p,r,color='g')
plt.plot(p,s,color='b')
plt.xlabel("w(in rad/s)")
plt.ylabel("Reactance")
plt.grid()
if a==3:
plt.plot(p,t,color='g')
plt.xlabel("w(in rad/s)")
plt.ylabel("Impedance")
plt.grid()
plt.title("plot of impedance as a function of w")
if a==4:
plt.subplot(3,1,1)
plt.plot(p,q,color='g')
plt.xlabel("w(in rad/s)")
plt.ylabel("Irms")
plt.grid()
plt.subplot(3,1,2)
plt.plot(p,r,color='b')
plt.plot(p,s,color='black')
plt.xlabel("w(in rad/s)")
plt.ylabel("XL")
plt.grid()
plt.subplot(3,1,3)
plt.plot(p,s,color='black')
plt.grid()
plt.xlabel("w(in rad/s)")
plt.ylabel("XC")
if a==5:
dictio={'w(in rad/sec)':p,'Irms(Ampere)':q,'Xl':r,'Xc':s,'R':u,'Z':t}
df1=pd.DataFrame(dictio)
print(df1)
if a==6:
for i in t:
if i==min(t):
k=t.index(i)
OUTPUT:
a)
b)
c)
d)
e)
f)
5. Newton Law of Cooling: A hot cup of coffee initially at a temperature of 80oC cools down according to
Newton law of cooling given by the equation
Ts = Ambient temperature
If the ambient temperature is 10oC & and cooling constant is K = 0.1 sec−1,
(a) Plot the variation of Temperature of coffee as a function of time. Vary time inthe interval [0:50 s] in
steps of 0.5 s.
(b) Repeat part (a) for K= 0.05 s−1 & 0.01 s−1. Plot all the three variations on the same plot & compare.
Hence, explain the affect of K on cooling of coffee.
a)INPUT:
import numpy as np
To = 80
Ts = 10
k = 0.1
t = np.arange(0,50+0.5,0.5)
T = Ts + (To-Ts)*np.exp(-k*t)
plt.plot(t,T)
plt.grid()
OUTPUT:
b) INPUT:
import numpy as np
To = 80
Ts = 10
k1 = 0.1
k2 = 0.05
k3 = 0.01
t = np.arange(0,50+0.5,0.5)
T1 = Ts + (To-Ts)*np.exp(-k1*t)
T2 = Ts + (To-Ts)*np.exp(-k2*t)
T3 = Ts + (To-Ts)*np.exp(-k3*t)
plt.grid()
plt.xlabel('Time')
plt.ylabel('Temperature')
plt.legend(['k1','k2','k3'])
OUTPUT:
CCL ASSIGNMENT
III
22
AIM:
20
• Learn to plot mathematical formula or data points in python using different libraries.
@
ge
Co I
HINT: To complete each exercise you should expect to use some or all of these Python
u s-
lle
features:
nd sic
• Use of matplotlib, math and pandas libraries of python
Hi hy
s, P
• Use subplot function to create multiple plots in a single graphic window for com-
parison of different sets of data.
Problems:
m
rt
pa
q(t) = q0 e(−t/RC)
1
2. Radioactive Decay: Radioactive decay of nuclei takes place according to the
equation
N(t) = N0 e(−λt)
Consider a radioactive nuclei with number of nucleons N0 = 1000 at t =0.
(a) Find number of nucleons remains after every 0.02 day if decay constant is λ = 1
days−1 . Display the data on the python console as data frame. Take time range [0:
5 days]
(b) From the given data frame, find the half life and mean life of the given radioactive
nuclei.
22
(c) Plot the variation of number of remaining nucleons as function of time.
20
@
3. Single Slit Diffraction: When LASER light falls on a single slit, diffraction phe-
nomenon produces a fringe pattern on the screen with peak brightness Io at the
ge
Co I
center. Intensity distribution as a function of diffraction angle can be described by
u s-
lle
the equation
nd sic
Hi hy
2
I(α) = I0 ( sinα
α )
s, P
sic cal
(a) Vary angle α in range [-10 radian :10 radian] in step of 0.1 radian and plot the
variation of I vs α. If any error is raised by the python interpreter then explain
hy ati
(b) Vary angle α in range [-10 radian :10 radian] in step of 0.09 radian and plot the
variation of I vs α. Take I0 = 1.
t o th
en Ma
is 5 volt.
rt
(a) Plot the variation of current Irms as a function of ω(rad/s). Vary ω from [500
pa
(b) Plot the variation of capacitive reactance and inductive reactance as a function
of ω in a single graph (using the same ω axis) .
(c) Also plot the variation of impedance (Z) as a function of ω.
(d) Plot above three graphs (of part (a), (b) & (c)) in a single graphic window as
separate plots using subplot.
(e) Create dataframe which display ω, Irms , XL , XC , R & Z. Display data frame on
the console.
(f) Use the given data frame to find value of ω called the Resonant Frequency
for which impedance is minimum and current is maximum.
2
5. Newton Law of Cooling: A hot cup of coffee initially at a temperature of 80o C
cools down according to Newton law of cooling given by the equation
22
the interval [0:50 s] in steps of 0.5 s.
20
(b) Repeat part (a) for K= 0.05 s−1 & 0.01 s−1 . Plot all the three variations on the
@
same plot & compare. Hence, explain the affect of K on cooling of coffee.
ge
Co I
u s-
lle
nd sic
Hi hy
s, P
sic cal
hy ati
f P em
t o th
en Ma
m
rt
pa
De