function Figure8_2

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

close all;
format long

% Figure 8.2(a)

load data_Figure8_2_a.dat
finaltime=200;
dt=0.01;
time=[0:dt:finaltime];
X=reshape(data_Figure8_2_a,length(time),10);
Xsecondhalf=X(round(length(time)/2):length(time),1:10);
w=size(Xsecondhalf);
pom=ones(w(1),10)*diag(Xsecondhalf(1,1:10));
Xsecondhalf(:,1:10)=Xsecondhalf(:,1:10)-pom;
ttt=time(round(length(time)/2):length(time));
pom=round((length(time)/2));
ttt=ttt-time(pom);

figure(1);
set(gca,'Fontsize',18);
plot(ttt,Xsecondhalf(:,1:10),'Linewidth',1);
xlabel('$t-100$','interpreter','latex');
ylabel('$X(t)-X(100)$','interpreter','latex','Fontsize',18);
box on;
axis([0 100 -17 17]);
set(gca,'Fontsize',18);

% Figure 8.2(b)

load data_Figure8_2_b.dat
finaltime=200;
dt=0.1;
time=[0:dt:finaltime];
X=reshape(data_Figure8_2_b,length(time),10);
XsecondhalfHO=X(round(length(time)/2):length(time),1:10);
w=size(XsecondhalfHO);
pom=ones(w(1),10)*diag(XsecondhalfHO(1,1:10));
XsecondhalfHO(:,1:10)=XsecondhalfHO(:,1:10)-pom;
ttt=time(round(length(time)/2):length(time));
pom=round((length(time)/2));
ttt=ttt-time(pom);

figure(2);
set(gca,'Fontsize',18);
plot(ttt,XsecondhalfHO(:,1:10),'Linewidth',1);
xlabel('$t-100$','interpreter','latex');
ylabel('$X(t)-X(100)$','interpreter','latex','Fontsize',18);
box on;
axis([0 100 -17 17]);
set(gca,'Fontsize',18);

