function Figure3_1b

% Matlab code for Figure 3.1(b) in book:
% Radek Erban and Jon Chapman, Stochastic Modelling of Reaction-Diffusion
% Processes, Cambridge University Press, 2019

close all;
randn('state',100);

dt=0.001;
finaltime=5; 

n=finaltime/dt;
numberofrealisations=6;
X=zeros(numberofrealisations,n);
time=[0:dt:finaltime];

for i=1:numberofrealisations
    dX = dt*ones(1,n)+sqrt(dt)*randn(1,n);   
    X(i,:)=cumsum(dX(1,:));             
end

figure(1);
set(gca,'Fontsize',18);
plot(time,[0,X(1,:)],'c');   
hold on;
plot(time,[0,X(2,:)],'m');   
plot(time,[0,X(3,:)],'g');   
plot(time,[0,X(4,:)],'Color',[0.9 0.9 0]);   
plot(time,[0,X(5,:)],'b');   
plot(time,[0,X(6,:)],'r');
line([0 5],[0 5],'Linewidth',2,'Linestyle','--','Color','k');
xlabel('$t$','interpreter','latex');
ylabel('$X$','interpreter','latex');
set(get(gca,'ylabel'),'rotation',0);
axis([0 5 -1.2 7]);
set(gca,'Fontsize',18);

