%                     Simulation of the Brusselator
clear
% Parameters
A=2.0;
B=5.2;
D1=2e-3;
D2=0;
% Numerical Parameters
n=101;
dt=0.01;
tmax=8;
% Plotting Parameters
tplot=0.1;

% SET UP initial values
s=linspace(0,1,n);
x=(2.5+2*(cos(2*pi*s)+sin(2*pi*s)))';
y=(3-1.5*(cos(2*pi*s)+sin(2*pi*s)))';

% SET UP Figures
clf   %  clear figures
%pict=plot(s,x,'r',s,y,'b','EraseMode','xor')
subplot(2,1,1)
pict1=plot(s,x,'r','EraseMode','xor');
subplot(2,1,2)
pict2=plot(s,y,'b','EraseMode','xor');

% step in time
t=0;
nsteps=0;
tp=tplot;
while t<tmax
   [x,y]=stepbruss(x,y,n,dt,A,B,D1,D2);
   t=t+dt;
  %storage
   nsteps=nsteps+1;
   bigx(:,nsteps)=x;
   bigy(:,nsteps)=y;
   bigt(nsteps)=t;
  %plots
   if t>=tp 
       tp=tp+tplot;
%       plot(s,x,'r',s,y,'b','EraseMode','none')
    set(pict1,'Xdata',s,'Ydata',x)
    set(pict2,'Xdata',s,'Ydata',y)
       drawnow;
   end
end
hold off
disp('Simulation ended')
%  Try plotting x vs t for the point s=0.87 (or so)
% at the command line, enter:
%   clf
%   plot(bigt,bigx(87,:))

%  Copy this code to another file and change it to
%  run starting where the previous simulation left off
%  (hint, bigx, bigy and bigt hold the variable values)
