Professional Documents
Culture Documents
Assignment 2
Assignment 2
Assignment 2
February 5, 2018
1 QUESTION 1
In [59]: import numpy as np
import matplotlib.pyplot as plt
In [60]: N=10000
n=([1,5,10])
mean= 2
var=3
x=np.linspace(0,10,100)
fig=plt.figure(figsize=(15,10))
In [62]: plt.show()
1
In [63]: #Cauchy
fig=plt.figure(figsize=(15,10))
def Histplot1(n,N,mean,var,k,x):
s=fig.add_subplot(3,2,k)
y=np.zeros((N))
for i in range(N):
for j in range(n):
y[i]+=np.random.standard_cauchy()
y[i]*=1/n
y=y[(y>-15)&(y<15)]
plt.hist(y,500,normed=True,color='g')
for i in range (len(n)):
Histplot1(n[i],N,mean,var,i+1,x)
In [64]: plt.show()
2
QSTN 2
February 5, 2018
In [241]: print(data)
lum redshift
0 345.2 0.100
1 66.3 0.040
2 684.0 0.070
3 209.0 0.050
4 16.0 0.020
5 91.0 0.050
6 16.3 0.050
7 19.4 0.040
8 310.5 0.020
9 124.9 0.070
10 137.9 0.001
11 93.1 0.120
12 53.6 0.050
13 122.1 0.040
14 25.4 0.020
15 26.3 0.001
16 196.9 0.090
17 68.8 0.060
18 82.0 0.020
19 8.4 0.001
20 319.3 0.170
21 86.8 0.020
22 8.7 0.001
23 37.7 0.001
24 3.4 0.001
25 166.0 0.060
1
26 104.2 0.030
27 45.0 0.090
28 14.5 0.001
29 38.1 0.030
30 17.8 0.030
31 31.1 0.040
32 89.0 0.040
33 66.3 0.060
34 17.7 0.050
35 4.5 0.001
36 69.1 0.050
37 1.1 0.001
38 6.2 0.001
39 47.2 0.050
40 23.4 0.001
41 160.8 0.060
42 6.4 0.020
43 5.1 0.030
44 134.5 0.030
45 4.1 0.001
In [242]: plt.scatter(np.log(lum),np.log(redshift),color='k')
In [243]: plt.ylabel('log(luminosity)')
plt.xlabel('log(redshift)')
plt.title('Luminosity and redshift of galaxy clusters')
plt.show()
2
In [244]: corr_coeff,p_value = stats.pearsonr(lum,redshift)
print('pearson corr. coeff:', corr_coeff ,',p value for null hypothesis:',p_value)
3
QSN 3
February 5, 2018
In [107]: wind=np.genfromtxt('wind.txt')
In [108]: x = wind[:,0]
y = wind[:,1]
In [110]: form_factor = 6
scale_factor = 2
dist = weibull_min(scale_factor,0,form_factor)
x1 = np.linspace(0,20,1000)
y = dist.pdf(x1)
1
2