Sign up ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I want to use perpendicular offsets in the built-in FindFit function. Are there any possible ways or do I have to code everything by myself?

share|improve this question
Mathematica does not yet have explicit support for orthogonal regression / total least squares, but one can certainly use the built-in optimization functions to implement this sort of fitting. – J. M. is back. May 7 '13 at 8:00
Look here – PlatoManiac May 7 '13 at 10:15
For Mathematica examples of orthogonal fitting, see this and this. – J. M. is back. May 7 '13 at 13:19

1 Answer 1

up vote 5 down vote accepted

Ok, I had done this long time ago since my supervisor insisted, this is a numerical approach to what you asked for and I have done this for a L-J potential function but can be extended to any function.

I hope this will help you.

In principle we need to minimize the the perpendicular distance. For example if U[r] is our function and E[r] is our energy points (data), we will have to different types of fitting

minimizing U[r]-E[r] =Vertical fit

minimizing U[x]-E[r] =perpendicular fit,

where x is the point on the curve which is perpendicular to our data point.

Problem here is we don't have any coordinates for points on our functional to draw perpendicular lines and minimize them, therefore what I did was doing a normal builtin fitting which would be vertical as an initial guess!

something like:

NMinimize[(U[r] -E[r] ), {A,B,C}]

Then I draw perpendicular lines from the first best vertical fit assumption and minimize them

for that!

you Find Perpendicular coordinates on to the line (here's the x we need!)

FindMinimum[{(E[x] - U[r])^2 + (x - r)^2}, {x,"initial guess"}]

Then minimize this distance by refitting in the same procedure as before but this time instead minimizing E[r]-U[r] you minimize E[r]-U[x] where x is perpendicular to E[r]. after this you can put it in a loop and continue this loop to satisfaction.

[Dotted line and red points are energy data, dashed line is perpendicular fit, red line is vertical fit1

share|improve this answer
it was long time ago but thanks you answered in great details with a nice numerical approach. – Raymond Ghaffarian Shirazi Sep 6 at 12:46

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.