function Figure7_6

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

close all;

datametropolis1=load('data_Figure7_6_a.dat');
metropolis1=reshape(datametropolis1,40,4);

noboxes=40;
D=0.0001;

xdet=[1/(2*noboxes):1/noboxes:1-1/(2*noboxes)]';
Sdet=(0.001/noboxes)*[0.5:1:(noboxes/2)-0.5 (noboxes/2)-0.5:-1:0.5]';
histdet=exp(Sdet/D);
integral=sum(histdet)/noboxes;
histdet=histdet/integral;

figure(1);
set(gca,'Fontsize',18);
hb1=bar(xdet,metropolis1(:,4)/25);
set(hb1,'FaceColor',[0.88 0.88 0.88]);
hold on;
plot(xdet,metropolis1(:,3)/25,'b','Linewidth',2);
plot(xdet,metropolis1(:,2)/25,'g','Linewidth',2);
plot(xdet,metropolis1(:,1)/25,'k','Linewidth',2);
plot(xdet,histdet,'or','Linewidth',5,'Markersize',3);
box on;
xlabel('$x$ [mm]','interpreter','latex');
ylabel('concentration [$\mu$m$^{-1}$]','interpreter','latex');
axis([0 1 0 4.7]);
hh1=legend('$I=10^8$','$I=10^7$','$I=10^6$','$I=10^5$','(7.65)');
set(hh1,'interpreter','latex','Fontsize',18);
set(gca,'Fontsize',18);

metropolis2=load('data_Figure7_6_b.dat');

figure(2);
set(gca,'Fontsize',18);
hb2=bar(xdet,metropolis2/25);
set(hb2,'FaceColor',[0.88 0.88 0.88]);
hold on;
stem(xdet,histdet,'or','Linewidth',1,'Markersize',0.1);
plot(xdet,histdet,'or','Linewidth',5,'Markersize',3);
box on;
xlabel('$x$ [mm]','interpreter','latex');
ylabel('concentration [$\mu$m$^{-1}$]','interpreter','latex');
axis([0 1 0 4.7]);
set(gca,'Fontsize',18);
