polyfit funktioniert, aber es gibt bessere kleine quadratische Minimizer da draußen. Ich würde kmpfit, erhältlich bei
http://www.astro.rug.nl/software/kapteyn-beta/kmpfittutorial.html
Es ist robuster, dass polyfit empfehlen, und es ist ein Beispiel auf ihrer Seite, die zeigt, wie eine einfache lineare Anpassung zu tun, die die Grundlagen zu tun, eine zweite Ordnung sorgen sollten polynomische Anpassung.
def model(p, v, x, w):
a,b,c,d,e,f,g,h,i,j,k = p #coefficients to the polynomials
return a*v**2 + b*x**2 + c*w**2 + d*v*x + e*v*w + f*x*w + g*v + h*x + i*y + k
def residuals(p, data): # Function needed by fit routine
v, x, w, z = data # The values for v, x, w and the measured hypersurface z
a,b,c,d,e,f,g,h,i,j,k = p #coefficients to the polynomials
return (z-model(p,v,x,w)) # Returns an array of residuals.
#This should (z-model(p,v,x,w))/err if
# there are error bars on the measured z values
#initial guess at parameters. Avoid using 0.0 as initial guess
par0 = [1.0, 1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0]
#create a fitting object. data should be in the form
#that the functions above are looking for, i.e. a Nx4
#list of lists/tuples like (v,x,w,z)
fitobj = kmpfit.Fitter(residuals=residuals, data=data)
# call the fitter
fitobj.fit(params0=par0)
Der Erfolg dieser Dinge hängt eng von den Startwerten für die Passform, wählte so sorgfältig, wenn möglich. Bei so vielen freien Parametern könnte es eine Herausforderung sein, eine Lösung zu finden.
Ich habe hier Code geschrieben, um dieses Problem zu lösen [https://github.com/mrocklin/multipolyfit](https://github.com/mrocklin/multipolyfit) – MRocklin