Last active
December 21, 2018 23:14
-
-
Save Uiuran/ceb1ccc6439f9f3c8ec4 to your computer and use it in GitHub Desktop.
Metodo monte-carlo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
from matplotlib import rc | |
dx = 0.001; | |
dy = 0.001; | |
alpha = 0.025; # quando alpha e beta != 0 teremos drift, isso eh, ddeslocamento do centro de massa | |
beta = 0.025; # | |
a = 0.25; # quando a = b = 1/4, difusao eh homogenea | |
b = 0.25; # | |
u = b -beta*dy*0.5 | |
r = a -alpha*dx*0.5 | |
d = b +beta*dy*0.5 | |
l = a +alpha*dx*0.5 | |
deslocamento = np.array([u, u+d,u+d+l,u+d+l+r]); | |
T = 1000 | |
x = []; | |
y = []; | |
for j in range(10000): | |
x.append([0.0]); | |
y.append([0.0]) | |
for i in range(T): | |
sorteio = np.random.uniform(0,1); | |
a = deslocamento.searchsorted(sorteio); | |
if a == 0: | |
y[j].append(y[j][-1]+dy); | |
x[j].append(x[j][-1]); | |
elif a == 1: | |
y[j].append(y[j][-1]-dy); | |
x[j].append(x[j][-1]); | |
elif a == 2: | |
x[j].append(x[j][-1]-dx); | |
y[j].append(y[j][-1]); | |
elif a == 3: | |
x[j].append(x[j][-1]+dx); | |
y[j].append(y[j][-1]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment