• Remix
  • Share
  • New Entry

on 6 Oct 2022
  • 6
  • 86
  • 1
  • 0
  • 280
% 2-D Stochastic Brusselator dynamics simulation
% Based on brusselator2_sde_milstein.m demo in my SDETools toolbox:
% https://mathworks.com/matlabcentral/fileexchange/56406
dt=5e-2; % Integration time step
n=64; % Dimension of the 2-D spatial grid
a=1; % Reaction constant
b=3; % Reaction constant
u=0.2; % Drift coefficient
v=0.02; % Drift coefficient
s=5e-2; % Noise magnitude
k=[0 1 0;
1 -4 1;
0 1 0]/4; % Laplacian convolution kernel
rng(1); % Set random seed
y=2*rand(n,n,2); % State matrices with random initial conditions
% Mask for borders
m=0*y;
m(2:n-1,2:n-1,:)=1;
for i=1:2e4 % Integration steps
X=y(:,:,1);
Y=y(:,:,2);
% 2-D Brusselator drift function using convolution
B=(b-Y.*X).*X;
f=cat(3,a-B-X+u*conv2(X,k,'s'),B+v*conv2(Y,k,'s'));
% 2-D Brusselator diffusion function
g=s*cat(3,-X,X);
% Euler-Maruyama integration of the SDE
y=y+m.*(f*dt+g*sqrt(dt).*randn(n,n,2));
end
imshow(y(:,:,1),[],'C',parula) % Scale and apply colormap
Remix Tree