MATLAB: Goodness of Fit – Error Bars

error barsfminsearchgoodness of fit

I'm currently using the fminsearch function in order to find a best fit curve to a non-analytic function. However, I would also like to be able to find error bars on my fit parameters, say at a 95% confidence level.
I don't have any experience with statistical analyses, and have been relying on built in fit functions to obtain error bars in the past. Is there any good way to do that without drastically altering my program?
To give a bit more information about my program: I am solving a system of equations with given parameters p(1), p(2), p(3), and then subtracting experimental data, x. The fminsearch function searches for optimal p by referencing a function (here, "functionname") which computes the quadratic mean (RMS) RMS(f(p)-x)
[poptimal, fval] = fminsearch(@functionname, p0);
I'd like to comment ahead of time that I don't want errorbars on the graph of my function or anything like that. I just want to know, for example, that p(1) is equal to 3e-6 +/- 2e-7 with 95% confidence.

Best Answer

I could be wrong, but I don't think that fminsearch() will be able to give you a canned goodness-of-fit error bar, because in a sense it does not "know" that you are doing a fit at all. You should theoretically be able to calculate it, but MATLAB isn't going to do it for you.
I believe the more standard approach for what you are doing would be to use the nlinfit() function in the Statistics Toolbox. That function produces error estimate output for the fitted parameters.