-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFig_1_RW_1D_Randomness.m
49 lines (44 loc) · 1.36 KB
/
Fig_1_RW_1D_Randomness.m
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
close all
clear all
clc
%% Parameters
Q = 10^4; %number of molecules
a = 10^-6;%radius of RN (m)
d = 10*10^-6; %distance of molecules to TN (m)
t = 0:0.05:10; %sampling period (s)
D = 10^-11; %Diffusion coefficient (m^2/s)
h = figure;
%%Random Walk 1-D
tau = 10^-3; %step time(s)
delta = sqrt(D*2*tau); %step length in m
setr = [1 -1];
temp = 1;
S = zeros(1, length(t));%initial number of molecules in V
for i = 1:length(t) %Simulation time in seconds
n = t(i)/tau; %Number of steps
for k = 1:Q %Loop of Molecules
%initial coordinate for each molecule
x = 0;
for j = 1:n %Movement of each molecule
x = x + delta.*setr(randi(length(setr)));
end
if abs(d-x) <= a
S(i) = S(i) + 1;
end
end
C_rw(i) = S(i)/(2*a); %concentration
end
plot(t, C_rw);
hold on;
%Theoretical
for i = 1:length(t)
C(i) = (Q/sqrt(4*pi*D*t(i)))*exp(-d^2/(4*D*t(i))); %single puff emission
end
plot(t, C, 'LineWidth',2);
xlabel('Time (s)');
ylabel('Molecule Concentration (molecules/m)');
legend('1-D Random Walk Simulation','Theoretical Model in (1)');
set(h,'Units','Inches');
pos = get(h,'Position');
set(h,'PaperPositionMode','Auto','PaperUnits','Inches','PaperSize',[pos(3), pos(4)]);
print(h,'Proof_Random','-dpdf','-r0')