-
Notifications
You must be signed in to change notification settings - Fork 0
/
pi.py
63 lines (37 loc) · 819 Bytes
/
pi.py
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
56
57
58
59
60
61
62
# Gisela Arrieta Rivera
#
import numpy as np
import matplotlib as mplt
import matplotlib.pyplot as plt
np.random.seed(0)
for j in range(7):
print np.random.random()
# Encontrar un numero aleatorio entre -1.5 y 1.5
R = 1
L = 3
N = 10000
y = 1.5-np.random.random() * 3
def pi(L, R, N):
x = np.linspace(0,1, num=N, endpoint='true')
n = 0
x=range(N)
y=range(N)
n = 0
for j in range(N):
x[j] = L/2 -np.random.random() * 3
y[j] = np.random.uniform(-1.5,1.5)
if np.sqrt(x[j]**2) + (y[j]**2)<=R:
n = n + 1
gpi= (L/R)**2 * (n/float(N))
print (np.pi, N, gpi)
# Definiendo la funcion rwalk1d
# p varia entre 0 y 100 porciento, entonces p va desde 0 hasta 1.0
def rwalk1d(N, p):
s = 0
for i in range(N):
r = np.random.random()
if r > p:
s = s + 1
else:
s = s - 1
return s