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 missing motivation– J. M.'s missing motivation2013-05-07 08:00:41 +00:00Commented May 7, 2013 at 8:00
- 3$\begingroup$ Look here cf.net16.net/odlsf $\endgroup$PlatoManiac– PlatoManiac2013-05-07 10:15:57 +00:00Commented May 7, 2013 at 10:15
- $\begingroup$ For Mathematica examples of orthogonal fitting, see this and this. $\endgroup$J. M.'s missing motivation– J. M.'s missing motivation2013-05-07 13:19:19 +00:00Commented May 7, 2013 at 13:19
1 Answer
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.
[
1
- $\begingroup$ it was long time ago but thanks you answered in great details with a nice numerical approach. $\endgroup$Raymond Ghaffarian Shirazi– Raymond Ghaffarian Shirazi2015-09-06 12:46:37 +00:00Commented Sep 6, 2015 at 12:46