function retval = lsqfn(x,P)
% usage:  y = lsqfn(x,P)
% description: returns least squares
% scalar function 1/2*||r(x)||^2
% good starting point: (-0.5,1.4), soln at (0,1)

% no bulletproofing

if (P == 1)
  retval = (x(1)+3)*(x(2)^3-7)+18;
else
  retval = sin(x(2)*exp(x(1))-1);
end