Does anyone know what algorithm Mathematica's basic Fit[] function uses? Is it proprietary?

I'm trying to do some pretty basic, linear, polynomial data fitting (albeit with poly degrees of about 15) in IDL but I'm finding that Mathematica's Fit[] function does a better job, and fails less often, than any of IDL's routines. So I was hoping to find out which algorithm Fit[] is using and translate it into IDL.

And for the record, if I use FindFit[..., Method->Automatic] it gives the same results as Fit[]. In another thread it was stated that FindFit[] defaults to the SVD algorithm if no Method is specified, so I wonder if this is the algorithm used by Fit[] as well (or perhaps just a matrix inversion).

Much appreciated.

  • $\begingroup$ Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$ – Michael E2 Mar 8 '16 at 23:16
  • 3
    $\begingroup$ Yes, it uses SVD under the hood. $\endgroup$ – J. M. is away Mar 8 '16 at 23:22
  • 3
    $\begingroup$ Almost certainly using SVD as @J.M. notes. For fitting degree 15 polynomials though you might want to consider a basis other than the standard one (1,x,x^2,...) to get better numeric stability. $\endgroup$ – Daniel Lichtblau Mar 8 '16 at 23:30
  • $\begingroup$ J. M. and Daniel, thanks. Daniel, maybe Legendre Polynomials? Interesting that IDL's svdfit() function and Mathematica's Fit[] function give very different results using SVD. I suppose the devil is in the details. $\endgroup$ – Adam Mar 9 '16 at 0:23
  • $\begingroup$ You could consider using Gram polynomials if your abscissas are equispaced; otherwise, the Chebyshev or Legendre basis can be used. $\endgroup$ – J. M. is away Mar 9 '16 at 0:54

Your Answer

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

Browse other questions tagged or ask your own question.