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(2)^3-7, 3*(x(1)+3)*x(2)^2];
else
  retval = [cos(x(2)*exp(x(1))-1)*x(2)*exp(x(1)), cos(x(2)*exp(x(1))-1)*exp(x(1))];
end