%Function goodnessOfFitPP outputs epsilon, the mean absolute distance
%between the measured trajectory of a bird, and its simulated trajectory 
%under proportional pursuit (PP) guidance, as generated by function fitPP.
%
%For details of function arguments, see documentation for fitPP.

function[epsilon]=goodnessOfFitPP(birdPos,birdVel,birdSpeed,lurePos,lureVel,stepSize,tauMax,K,tau)
  
    %Calls function fitPN to generate simulated position of bird
    simPos=fitPP(birdPos,birdVel,birdSpeed,lurePos,lureVel,stepSize,tauMax,K,tau);
    
    %Computes the mean absolute distance epsilon between the bird's simulated 
    %and measured positions. 
    epsilon=sum(sqrt(sum((birdPos-simPos).^2,2)))/(length(birdPos)-tauMax);
        %Note that rows 1:tauMax of simPos are identical to the corresponding 
        %rows of birdPos, because the simulation only begins at time step tauMax, so 
        %these identical datapoints  do not contribute to the calculation of epsilon.    
end