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?

  • $\begingroup$ 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. $\endgroup$ – J. M.'s ennui May 7 '13 at 8:00
  • 3
    $\begingroup$ Look here cf.net16.net/odlsf $\endgroup$ – PlatoManiac May 7 '13 at 10:15
  • $\begingroup$ For Mathematica examples of orthogonal fitting, see this and this. $\endgroup$ – J. M.'s ennui May 7 '13 at 13:19

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

  • $\begingroup$ it was long time ago but thanks you answered in great details with a nice numerical approach. $\endgroup$ – Raymond Ghaffarian Shirazi Sep 6 '15 at 12:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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