Created
February 14, 2013 14:16
-
-
Save ikautak/4953095 to your computer and use it in GitHub Desktop.
scipy leastsq sample.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import numpy as np | |
from scipy.optimize import leastsq | |
def fit_func(parameter, x, y): | |
a = parameter[0] | |
b = parameter[1] | |
residual = y - (a*x*x + b) | |
return residual | |
px = [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5] | |
py = [25.5, 16.9, 9.7, 4.3, 2.1, 1.02, 1.98, 4.9, 9.9, 15.8, 25.7] | |
px = np.array(px) | |
py = np.array(py) | |
parameter0 = np.array([0, 0]) | |
result = leastsq(fit_func, parameter0, args=(px, py)) | |
print result[0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment