Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random as rand
- import matplotlib.pyplot as plt
- import math
- def er():
- x = 0
- for i in range(2):
- x+= rand.expovariate(6)
- return x
- tc = 0
- N = 10000
- k = 0
- u =[]
- lo = 1000
- vo = 1000
- check = 1
- NG = []
- lG = []
- vG = []
- while check:
- NG.append(N)
- while k<N:
- u.append(er())
- tc+=u[k]
- k+=1
- mu = tc/N
- sum2 = 0
- for i in range(N):
- sum2+=(u[i] - mu)**2
- qu = (sum2/N)**(1/2)
- ln = 1/mu
- vn = qu/mu
- lG.append(ln)
- vG.append(vn)
- if math.fabs((ln - lo)/lo)>0.01 or math.fabs((vn - vo)/vo)>0.01:
- lo = ln
- vo=vn
- N*=2
- else:
- check = 0
- lr = [1 for i in range(len(NG))]
- vr = [1 for i in range(len(NG))]
- print(u)
- plt.figure(1)
- plt.plot(NG,lG)
- plt.plot(NG,lr)
- plt.figure(2)
- plt.plot(NG,vG)
- plt.plot(NG,vr)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement