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

function[epsilon]=goodnessOfFitPNP(birdPos,birdVel,birdSpeed,lurePos,lureVel,stepSize,tauMax,NK,tau)
  
    %Calls function fitPNP to generate simulated position of bird
    simPos=fitPNP(birdPos,birdVel,birdSpeed,lurePos,lureVel,stepSize,tauMax,NK,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