-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex6.2.py
More file actions
55 lines (34 loc) · 1.02 KB
/
ex6.2.py
File metadata and controls
55 lines (34 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Jan 22 17:11:58 2020
@author: astro
"""
import numpy as np
from numpy import random
import matplotlib.pyplot as plot
N=100000
#inizializzazione delle variabile dove memorizzare i valori
r=np.zeros(N,float)
t=np.zeros(N,float)
x=np.zeros(N,float)
y=np.zeros(N,float)
Pr=np.zeros(N,float)
Pt=np.zeros(N,float)
sigma=2.
for i in range(N):
#seed identifier of the random sequence
random.seed(None)
#generation of r and theta
Pr[i]=np.random.rand()
r[i]=(-2*(sigma**2)*np.log(1-Pr[i]))**0.5
Pt[i]=np.random.rand()
t[i]=2*np.pi*(Pt[i])
#calculation of the values of x and y, random variables independent of each other, normally distributed
x[i]=r[i]*np.cos(t[i])
y[i]=r[i]*np.sin(t[i])
plot.hist(x,bins=60, histtype='bar')
plot.hist(y,bins=60, histtype='step')
plot.xlabel('$x$',fontsize=12)
plot.ylabel('$PDF(x)$',fontsize=12)
plot.show()