function [res] = alge_odr_hook (what, x, b);
%ALGE_ODR_HOOK
%       
%       Function called by odr, 
%       wants either 'f' or 'df'
%
%       See also ODR.

  xc = x(:,1) - b(1)*ones(size(x,1),1);
  yc = x(:,2) - b(2)*ones(size(x,1),1);

  if     (strcmp(what, 'f')),
    res = b(3)*xc.^2 + 2*b(4)*xc.*yc + b(5)*yc.^2 - ones(size(x,1),1);
  elseif (strcmp(what, 'df')),
    res = zeros(size(x,1),7);
    res(:,6) = 2*b(3)*xc + 2*b(4)*yc;
    res(:,7) = 2*b(5)*yc + 2*b(4)*xc;
    res(:,1) = -res(:,6);
    res(:,2) = -res(:,7);
    res(:,3) = xc.^2;
    res(:,4) = 2*xc.*yc;
    res(:,5) = yc.^2;
  else
    str = sprintf ('unknown command: %s', what);
    error (str);
  end

end % alge_odr_hook
