Example: Using minerr for Nonlinear Least Squares Fitting
The minerr function is similar to the find function, except that it returns an approximate solution for some cases for which find reports that no solution exists.
1. Define two vectors.
2. Define a fitting function (Weibull density with unknown parameters).
3. Define initial guess values for the two parameters.
4. Use an equation to minimize inside a solve block.
5. Add a solve block and use minerr to solve the problem. The minerr function uses the Levenberg-Marquardt method to minimize this problem. The Levenberg-Marquardt method does its own summing and squaring of the residuals.
The parameters for best fit are the calculated values:
The find function fails to find a solution to the above problem.
6. Calculate the sum of squares implicitly minimized by this method.
7. Plot the best Weibull fit versus the x-y data.
8. Evaluate the mean squared error. If the mean is zero, then a true solution exists:
You can minimize directly by using the SSE equation and the minimize function.