Sign up ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I need to implement the algorithm described below. Everything is fine until the eigenvalues computation. I'm completely new to them and I found a lot of very complicated paper on the net. Is it possible that this 'best-fitting plane' case requires such a complex approach? Where can I find straightforward implementation of a suitable eigenvalue solver for this?

I am also interested in different approaches to the 'best-fitting plane' problem.


xm = mean(x); ym = mean(y); zm = mean(z);

u = x - xm; v = y - ym; w = z - zm;

M = [sum(u.^2),sum(u.*v),sum(u.*w); ...
     sum(v.*u),sum(v.^2),sum(v.*w); ...

[V,D] = eig(M);

Now choose the smallest eigenvalue in D. The corresponding eigenvector in V gives the coefficients, v1, v2, v3, in the best-fitting plane:

v1*(X-xm) + v2*(Y-ym) + v3*(Z-zm) = 0

By the way, if that smallest eigenvalue should turn out to be zero, that is your indication that the four points are coplanar and your plane is an exact fit.

share|cite|improve this question
Yes, this is the correct approach for the best-fitting plane. To get useful responses where to find a suitable eigenvalue solver, you should probably tell us more about your computing environment and requirements. – joriki Nov 14 '11 at 9:43
Bleh, I don't recommend this method, though. Better to use SVD instead of the eigendecomposition for these matters... – J. M. Nov 14 '11 at 9:52
@J.M.: I don't understand -- since $M$ is symmetric, isn't that the same thing? – joriki Nov 14 '11 at 9:58
@joriki: theoretically, yes. Computationally, a bad idea, since the cross-product matrix's condition number is the square of the condition number of the design matrix. See this previous answer of mine, where I show a simple example due to Läuchli. – J. M. Nov 14 '11 at 10:56
@J.M.: Ah, I see, sorry -- I thought you were suggesting to apply SVD instead of eigendecomposition to the covariance matrix :-) – joriki Nov 14 '11 at 11:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.