Advertisement
Carlettos

23.c

Oct 23rd, 2020
2,216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. import random as rnd
  2. import matplotlib.pyplot as plt
  3. # import ganas.de.vivir as suicidio
  4.  
  5.  
  6. def browniano(n, μ, σ):
  7.     x = [0]
  8.     y = [0]
  9.  
  10.     for i in range(n):
  11.         dx = rnd.normalvariate(μ, σ)
  12.         dy = rnd.normalvariate(μ, σ)
  13.         x.append(x[i] + dx)
  14.         y.append(y[i] + dy)
  15.         pass
  16.     return x, y
  17.  
  18.  
  19. σ = 1
  20. μ = 0
  21. tiempos = [100, 500, 1000, 5000, 10_000]
  22. k = 100
  23. for n, t in enumerate(tiempos):
  24.     promedio = 0
  25.     for j in range(k):
  26.         x, y = browniano(t, μ, σ)
  27.         # plt.subplot(k, len(tiempos), n*k + 1 + j)
  28.         # plt.plot(x, y)
  29.         # plt.title(f"t = {t}, intento = {j + 1}")
  30.         promedio += sum([x1**2 + y1**2 for x1, y1 in zip(x, y)])/t
  31.     print(f"promedio en t = {t}: {promedio/k}")
  32.  
  33. # plt.show()
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement