Least-square fitting
For database (x[i], y[i]), we know there is functional relation called y=f(x), we know the f(x) as the f(x) = f(x, p), p is the set of undetermined coefficient. We need to know the p to make S the least :
$$
S(p) = sum_{i=1}^{m}[y_i - f(x_i, p)]^2
$$
We use the bank optimize in scipy to realize the function of leastsq.
Here is the example. We are trying to fit a sine wave function.
1 |
# -*- coding: utf-8 -*- |
Here is the result.
近期评论