curve_fit
curve_fit(const List x, const List y, const Function<real(List,List)> f, Map options) -> Map
Fits the input data , to a user specified function with parameters .
Performs least squares fitting on an input funtion to input data. The funciton must be of a single variable , this function does not currently support higher dimensional curve fitting. The default algorithm used to minimize the erorr is Nelder-Mead.
Parameters
- x: The input data corresponding to the x data for the fit.
- y: The input data corresponding to the y data for the fit.
- f: The objective function to minimize. Must be of the form where is a real number and is a list of real parameters.
- options: Map containing optimization settings.
Returns
Map containing optimization results.
Example
// Curve fit to -2.32x + 0.23
def myfunc(List x, List p)
{
return real(p[0]*x[0] + p[1])
}
var options = ["lb": [-10.0,-10.0],
"ub": [5.0,5.0],
"p_init": [0.2,0.1],
"xtol" : 1e-4]
var x = [1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0]
var y = [2.09,4.41,6.73,9.05,11.37,13.69,16.01,18.33,20.65,22.97]
var result = curve_fit(x,y,myfunc,options)
print(result)