The six lines of Matlab code below is a nice way to fit an ellipse to a set of points. It is presented in a paper here:

Direct Least Square Fitting of Ellipses
But I'm looking for a measure of how good the fit is, how scattered the points are around the fitted ellipse. Something like the mean square error in regression. Can such a measure be derived from this code? If not, how could it be calculated in a computationally efficient way?

(I'm lost because of the magic of eigenvalue, so I don't really understand what the code actually does)

% fitellip gives the 6 parameter vector of the algebraic circle fit

% to a(1)x^2 + a(2)xy + a(3)y^2 + a(4)x + a(5)y + a(6) = 0

% X & Y are lists of point coordinates and must be column vectors.

% Build design matrix

D = [ x.*x x.*y y.*y x y ones(size(x)) ];

% Build scatter matrix

S = D'*D;

% Build 6x6 constraint matrix

C(6,6) = 0; C(1,3) = -2; C(2,2) = 1; C(3,1) = -2;

% Solve eigensystem

[gevec, geval] = eig(S,C);

% Find the negative eigenvalue

[NegR, NegC] = find(geval < 0 & ~isinf(geval));

% Extract eigenvector corresponding to positive eigenvalue

A = gevec(:,NegC);