-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_rms_ramdom_walk.py
72 lines (58 loc) · 1.5 KB
/
plot_rms_ramdom_walk.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
63
64
65
66
67
68
69
70
71
72
import matplotlib.pyplot as pl
from pylab import *
import numpy as np
from math import*
n=int(input("Digite el numero de N pasos: "))
k=int(sqrt(n))
todo=[]
# incisos a), b), c)
def grande(n,todo):
Rms=[]
#inciso a)
def camaleat():
sumx=0.0
sumy=0.0
x = np.zeros(n)
y = np.zeros(n)
for i in range(1,n):#genera numeros normalizados
x[i]=(np.random.rand()-0.5)* 2. # −1 =< x =< 1
y[i]=(np.random.rand()-0.5)* 2. # −1 =< y =< 1
L=sqrt(x[i]**2 + y[i]**2)
x[i]=x[i]/L
y[i]=y[i]/L
for i in range(1,n):
sumx+=x[i]
sumy+=y[i]
Rms.append(sumx**2+sumy**2)
camaleat()
#inciso b)
def kexperimentos():
for i in range(1,k):
np.random.seed(None)
camaleat()
kexperimentos()
#inciso c) obtener el valor esperado para k caminatas
def vespR(Rms,n):
Total=0.0
for i in range(k):
Total+=Rms[i]
Total=Total/k
todo.append(Total)
print(f'EL valor de <R^2({n})> es: {Total}')
vespR(Rms,n)
for i in range(n+1):
grande(i,todo)
#inciso e)
def grafica(todo):
N=[]
for i in range(n+1):
N.append(sqrt(i))
todo[i]=sqrt(todo[i])
lin=[0,N[n-1]]
pl.title(f"Rrms en funcion de raiz de N")
pl.plot(N,todo,'b',linewidth=0.8)
pl.plot(N,N,'g')
pl.xlabel("sqrt(N)")
pl.ylabel("Rrms")
pl.show()
grafica(todo)