-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSDE_simulate_ternary.m
49 lines (44 loc) · 1.19 KB
/
SDE_simulate_ternary.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
%Author: Jitesh Jhawar
%Date:25/09/2018
%This code simulates the numerical integration of a stochastic differential
%equation of ternary interaction model
n = 50000001;
x = zeros(n,1);
time = zeros(n,1);
x(1,1) = 0.1;
del_t = 0.01;
i = 1;
N = 400; % system size
s = 0.05; % spontaneous rate
c = 0.005; % pairwise interaction rate
h = 0.21; % ternary interaction rate
% simulation begins
while i ~= n-1
diff = 4/N*(s+(2*c+h)*(1-x(i,1)^2)/4);
%ensuring that diffusion is not negative by redoing the previous time step
if (diff < 0)
i = i - 1;
end
% stochastic function
diff = 4/N*(s+(2*c+h)*(1-x(i,1)^2)/4);
% determinisic function
drift = -2*s*(x(i,1))+(x(i,1)*(1-x(i,1)^2)*h/2);
%random number
r = randn(1,1);
%calculating value at next time step using Euler method and ito's
%interpretation
x(i+1) = x(i) + (drift)*del_t + r*(diff)^0.5*(del_t^0.5);
time(i) = (i*del_t);
i = i + 1;
end
%Plotting
figure,
plot(time,(x))
xlabel('time','fontweight','bold')
ylabel('OP from SDE','fontweight','bold')
ylim([-1,1])
figure,
hist((x),100)
xlabel('\rho','fontweight','bold','FontSize',22)
ylabel('Counts','fontweight','bold','FontSize',18)
% xlim([0,1])