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

% 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')
