function a = epsproj(XYmax,A,Apos,B,Bpos,N,dt,K,RatioAB)
%XYmax is a vector with 2 elements aka room dimensions.XYmax(1) is x
%dimension. XYmax(2) is y dimension.
%A is the amount of gas A in the room.
%B is the amount of gas B in the room.
%Apos is a vector with x and y coordinates where A starts.
%Bpos is a vector with x and y coordinates where B starts.
%N is the number of time steps into the future.
%dt is the change in time.
%K is the reactant constant.
%RatioAB is a two element vector that contains the ratio it takes 
% to make one unit of C. i.e. RatioAB(1)*A+RatioAB(2)*B -> C

%setting up the matrices.
AM=zeros(XYmax(2),XYmax(1));
BM=zeros(XYmax(2),XYmax(1));
CM=zeros(XYmax(2),XYmax(1));

%setting up the point sources for the gases.
AM(Apos(1),Apos(2))=A; 
BM(Bpos(1),Bpos(2))=B;

%conter variable for taking images
f=0;

%iteration for N steps.
for i=1:N

    %diffusion of gas A,B and C
    AM=IterateMatrix(AM,XYmax);
    BM=IterateMatrix(BM,XYmax);
    CM=IterateMatrix(CM,XYmax);

    %check if A and B gases have moved to the same spot. if yes, reaction
    %occurs
    for x= 1:XYmax(2)
        for y=1:XYmax(1)
            if (AM(x,y)*BM(x,y) ~=0)
                dC=K*AM(x,y)*BM(x,y)*dt;
                dA=-K*AM(x,y)*BM(x,y)*RatioAB(1)*dt;
                dB=-K*AM(x,y)*BM(x,y)*RatioAB(2)*dt;
                AM(x,y)=AM(x,y)+dA;
                BM(x,y)=BM(x,y)+dB;
                CM(x,y)=CM(x,y)+dC;
            end
        end
    end
    

    
    % plotting
                
    xx=1:XYmax(1);
    yy=1:XYmax(2);
    [X,Y]=meshgrid(xx,yy);
    surf(X,Y,BM);
    view([+34.5 14]);


  % if mod(i+9,10)==0
   % f=f+1;
    %saveas(gcf, ['proja',sprintf('%03d',f),'.png'])  %%saving files

    %end

end
 










end