%
%     BALLSPORE
%
%     a Matlab M-file which models ballistic dispersal of fungi in 1-D
%

pold = pnew;          % define initial condition, this step --  
                      %     USER MUST DEFINE THE FIRST pnew 
                      %     BEFORE RUNNING THIS PROGRAM

KB=1./(pi*sqrt(c^4/g^2-x.^2)).*(abs(x) <= c^2/g);
                  % define dispersal kernel, taking care that it is zero in 
                  %   the right places

KB=KB/trapz(dx*KB);
                  % this normalizes the probability kernel.  Because of 
                  %   the singularities at the ends this is an important
                  %   step -- otherwise there will be net loss

fKB=dx*fft(KB);   % Take FFT of dispersal kernel, multiplying by dx to save
                  %   that step later

fpnew = fKB.*fft(pold);
                  % FFT of new dispersed population
pnew = real(fftshift(ifft(fpnew)));
                  % new dispersed population

hold on, plot(x,pnew,'r'), hold off
                  % plot results on current figure
