function retval = errornorms(A,B,C,E,X,Y,M,D,a,dr,T,dt,RadialDist,count)
% usage: retval = errornorms(A,B,C,E,X,Y,M,D,a,dr,T,dt,RadialDist,count)
% description: returns average relative error norm for model data
% input. Errors are obtained with p = 0.1, 0.5, 1.0.  These are
% hard-wired into the routine, but easily changed. No error checking.

% for predictability...unrem the next line
rand('seed',2);
pr = [1,0.5,0.1]; % first probability must be 1
retval = zeros(size(pr));
lenpr = length(pr);
timenodes = linspace(0,dt*T,T+1);
% find max radius
radmax = max([norm([X,Y]-[A,C]),norm([X,Y]-[A,E]), ...
        norm([X,Y]-[B,C]),norm([X,Y]-[B,E])]);
radii = ceil(radmax/dr); % number of space steps
spacepoints = linspace(dr/2,dr*(radii-0.5),radii);
timepoints = linspace(dt/2,dt*(T-0.5),T);
retval = zeros(size(pr));
% calculate norm of N(r,t)
integrand = zeros(size(spacepoints));
for ii = 1:T
  integrand = integrand + ...
  (Nsoln(spacepoints,timepoints(ii),M,D,a).^2).*spacepoints;
end
normN = sqrt(sum(integrand)*dr*dt);
% calculate error norm for p = 1
P = pr(1);
events = RadSim(A,B,C,E,X,Y,M,D,a,dr,T,dt,P,RadialDist);
cumulprofiles = RadialProfiles(X,Y,dr,timenodes,events);
[m,n] = size(cumulprofiles);
if (n < radii) % pad the profiles
  cumulprofiles = [cumulprofiles,zeros(m,radii-n)];
end
integrand = zeros(size(spacepoints));
for ii = 1:T
  integrand = integrand + (cumulprofiles(ii,:) - ... 
  Nsoln(spacepoints,timepoints(ii),M,D,a)).^2.*spacepoints;
end
retval(1) = sqrt(sum(integrand)*dr*dt);
% calculate the errors with probability less than 1
for ii = 2:lenpr
  P = pr(ii);
  % accumulate profile samples
  for jj = 1:count
    events = RadSim(A,B,C,E,X,Y,M,D,a,dr,T,dt,P,RadialDist);
    profiles = RadialProfiles(X,Y,dr,timenodes,events);
    [m,n] = size(profiles);
    if (n < radii) % pad the profiles
      profiles = [profiles,zeros(m,radii-n)];
    end
    cumulprofiles = cumulprofiles + profiles;
  end
  cumulprofiles = cumulprofiles/count;
  integrand = zeros(size(spacepoints));
  for kk = 1:T
    integrand = integrand + (cumulprofiles(kk,:)- ...
    Nsoln(spacepoints,timepoints(kk),M,D,a)).^2.*spacepoints;
  end
  retval(ii) = sqrt(sum(integrand)*dr*dt);
end
retval = retval/normN;
end

