What function can fit this line better?

The plot below was created using functions that needed to have coefficients optimized to have the least error by this line: Coeff{n,1} = lsqnonlin(@(C)ModelObj(C,DataFilter),x0,lb,ub);. The optimization is not giving good coefficients for the fit and it's only using the top points while ignoring the bottom points. The data set has a wide range, so is there another function I can use that normalizes or weights the data equally so that I get a better fit?

 Accepted Answer

John D'Errico
John D'Errico on 2 Aug 2017
Edited: John D'Errico on 2 Aug 2017
This happens because you are doing the fit in the wrong way.
Yes, you can do a weighted nonlinear regression fit.
But the simplest solution is to log your model, then use it to fit the log of your y data. This is almost always the right choice when your data spans multiple orders of magnitude.
To then plot actual predictions in the original space, don't log the model.
Of course, it is also possible that you have the wrong model. But in any case, you still need to work in a log-transformed domain.

2 Comments

If he had attached the data, someone with spare time might have tried some code on it.
How would I do it with a weighted nonlinear regression fit? I also tried doing what was advised and loging the initial data but the prediction didn't seem accurate. I got partially lost in loging the model, do you mean to convert my equations into a log form? I have attached my experimental data. The image above uses this formula where C are the constants and X are the column inputs. fun= @(C,X) C(1).*((sinh((X(:,2)./C(3)))).^C(2))+C(4)+C(5); My initial condition was obtained by using excel x0 = [.00000015, .69, 15, 0, 0]; Any other information pertaining to the code that might help in the process I can easily give out too.

Sign in to comment.

More Answers (0)

Categories

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!