function e=mmnlfit_(p,x,y,z,fun)
%MMNLFIT_ Helper function for MMNLFIT and MMNLFIT2. (MM)
% MMNLFIT_(P,X,[],'FUN') is used by MMNLFIT as the
% function to pass to FMINS for minimization.
% MMNLFIT_(P,X,Y,'FUN') is used by MMNLFIT2 as the
% function to pass to FMINS for minimization.

% D.C. Hanselman, University of Maine, Orono, ME 04469
% 7/14/96
% Mastering MATLAB, Prentice Hall, ISBN 0-13-191594-0

if isempty(z)
	e=y - feval(fun,x,p);
else
	e=z - feval(fun,x,y,p);
end
e=e(:);
e=e'*e;
