function [z, a, b, alpha, err] = alge_simple (X, show);
%ALGE_SIMPLE    Algebraic least squares ellipse fit.
%       
%       [z, a, b, alpha, err] = alge_simple (X, show{default 0})
%       fits an ellipse by minimizing the "algebraic distance"
%       in the least squares sense x'A x + b'x + c = 0
%       weighting the i-th data by W(i).
%       Constraint: A11 + A22 == 1.
%
%       X: given points Pi = [X(i,1), X(i,2)]
%       show: if (show == 1) make test output
%
%       z, a, b, alpha: parameters for found ellipse
%       err: error indication
%       if (err == 1), not an ellipse
%       if (err == 0), ok

  if (nargin < 2), show = 0; end;

  b = -X(:,1).^2;
  A = [X(:,1).*X(:,2), X(:,2).^2-X(:,1).^2 ...
       X(:,1) X(:,2) ones(size(X(:,1)))];
  x = A\b;
  u = [1-x(2);x];

  [z, a, b, alpha, err] = ellipse_params (u, show);

end % alge_simple
