Sem 5
Sem 5
Sem 5
: 144-1111-0302-21
##autocorelation
import numpy as np
def random_lcg(x,size):
a,c,m=2416,37441,1771875 #given
X=[]
for i in range(size):
x=(a*x+c)%m
r=x/m
X.append(r)
return X
l=random_lcg(seed, N)
#Autocorelation
l_avg=np.mean(1)
r=lambda k: c(k)/c(0)
plt.subplot(121)
plt.hist(1,bins=40, edgecolor='black')
plt.subplot(122)
plt.title('Autocorelation')
plt.plot(corr)
plt.savefig('autoc1.png')
plt.show()
'''
OUTPUT
'''
##regn. no. : 144-1111-0302-21
import numpy as np
return I[0]
Dulong_Petit=np.ones(10000)
Einstein=lambda Temp:
(Theta_E/Temp)**2*np.exp(Theta_E/Temp)/(np.exp(Theta_E/Temp)-1)**2
print("OUTPUT")
plt.xlim(0,50)
plt.ylim(0,1.15)
plt.xlabel("Temperature")
plt.ylabel("C_V")
plt.savefig('dulong.png')
plt.grid()
plt.show()
import numpy as np
def T_distribution(Temperatures):
for T in Temperatures:
plt.ylim(0,1.5)
plt.xlabel('E')
plt.ylabel(' Distribution')
plt.legend()
plt.savefig("mbfdbe3.png")
plt.show()
T_distribution(Temperatures)
plt.show()
##regn. no. : 144-1111- FERMI-DIRAC DISTRIBUTION 0302-21
MAXWELL-BOLTZMANN DISTRIBUTION
##monte carlo
import numpy as np
def f(x):
return x/(1+x*x)
x=np.random.uniform(a,b,N)
return (b-a)*np.mean(f(x))
I=MonteCarlo (a,b,N,f)
print("OUTPUT")
'''
OUTPUT
OUTPUT
'''
import numpy as np
N=10000
mu=1
sigma=0.5
x=np.random.normal(mu,sigma,N)
plt.savefig('normal.png')
plt.hist(x)
plt.show()
##regn. no. : 144-1111-0302-21
import numpy as np
number=nloop=NO
N,Time=[NO], [0]
decay=np.random.random()
if(decay<lam):
nloop=nloop-1
number=nloop
N.append(nloop)
Time.append(time)
T=np.array(Time)
NN=NO*np.exp(-lam*T)
plt.plot(Time, NO-NN)
plt.xlabel("time,t")
plt.savefig('nuclear.png')
plt.show()
'''
OUTPUT
'''
##regn. no. : 144-1111-0302-21
import numpy as np
N=10000
a=1
b=100
x=np.random.uniform (a,b,N)
plt.savefig('random2.png')
plt.hist(x)
plt.show()
##regn. no. : 144-1111-0302-21
import numpy as np
N=10000
a=1
b=100
x=np.random.randint(a,b,N)
plt.savefig('hist1.png')
plt.hist(x)
plt.show()
import numpy as np
m=int(input('Enter mean:'))
exp=np.random.exponential (m,size=10000)
plt.subplot(121)
plt.title('Exponential distribution')
plt.subplot(122)
plt.title('Normal distribution')
plt.hist(x,bins=40, edgecolor='red')
plt.savefig('rnd.png')
plt.show()
'''
OUTPUT
Enter mean:5
'''
##regn. no. : 144-1111-0302-21
import numpy as np
N=10000
m=10#mean
x=np.random.exponential (m,N)
plt.savefig('expnumber.png')
plt.hist(x)
plt.show()
##Simulate unbiased random walk in 1D. Plot of r.m.s. value of end to end
distance as a function of time step. Fit the data and find the exponents.
import numpy as np
number=100
time=1000
x=2*np.random.randint(0,2,size=(number, time))-1
pos=np.cumsum(x, axis=1)
pos_sq=pos**2
rms=np.sqrt(m_pos_sq)
t=np.arange(1,1001,1)
sq_t=np.sqrt(t)
t=np.log(t)
sq_t=np.log(sq_t)
rms=np.log(rms)
print("OUTPUT: ")
plt.plot(t,rms, 'o')
plt.plot(t,sq_t)
plt.savefig('rndwalk.png')
plt.show()
##regn. no. : 144-1111-0302-21
import numpy as np
N=200
m=100
H=np.zeros(200)
T=np.zeros(200)
for j in range(N):
a=np.random.randint(0,2,100)
h=0
t=0
for i in range(m):
if(a[i]==0):
h=h+1
else:
t=t+1
H[j]=h
T[j]=t
plt.hist(H)
plt.savefig('single.png')
plt.show()
'''
OUTPUT
'''
##regn. no. : 144-1111-0302-21
"""
"""
import numpy as np
u=np.random.uniform(0,1,size=10000)
plt.subplot(121)
plt.title('Uniform distribution')
plt.hist(u,bins=40, edgecolor='red')
plt.subplot(122)
plt.title('Normal distribution')
plt.hist(x,bins=40, edgecolor='red')
plt.savefig('random3.png')
plt.show()
'''
OUTPUT
'''