Minerr/nonlinear optimizing
- July 1, 2016
- 2 replies
- 14581 views
In reference to this document: Minerr/nonlinear optimizing
Your equation for Function is wrong. For a least squares fit the error function should be the square root of the sum of the squares (or just the sum of the squares). You have the sum of the square root of the squares, which is equivalent to the sum of the absolute values. See my Function2 for the correct error function.
Having said that, the best way to fit a function to experimental data is to create a function that generates the vector of residuals: see my Function3. Feed that directly to minerr, and use the Levenberg-Marquardt option.
Minimizing Function gives an error (i.e. Function2) of 1721, 311, or 133, depending on the algorithm used
Minimizing Function2 gives an error (i.e. Function2) of 1628, 109, or 100, depending on the algorithm used
Minimizing Function3 using the LM algorithm gives an error (i.e. Function2) of 261
I'm not sure why the last option does not give an error as low as a couple of the other options, except to say it has to do with where the minimization ends. Using a vector of residuals with the LM algorithm, maybe it takes a slightly different path and gets trapped somewhere in a local minimum. Changing the guesses may help. Nevertheless, despite the fact that the error is slightly higher in this example, in general this is the best approach.
