MATLAB Curve fitting with custom equation
Show older comments
Hello,
I have a data (x,y) points and I want to fit it with custom equation as y = a*(1-exp(-b*x))+c*(exp(d*x)-1). I want to get a, b, c, d values after fitting with custom equation.The problem I am facing is that, the curve fitting happens to be good in the initial part of the data points, then at the later points of data, it does not fit properly. How to tweak with fitoptions so that I can fit my data exactly with custom equation. Also, if there needs any change to be done in the script please help me with that too, so that I can fit it exactly. If you can provide me snaps of the script that you are following to fit kindly share that too as it will help me to understand properly.
I am attaching the data file for your reference.
Thank you
14 Comments
J. Alex Lee
on 29 Oct 2020
Edited: J. Alex Lee
on 29 Oct 2020
- You can't ever fit your data "exactly" (in principle), unless you only have as many data points as you have free parameters, or if your data was generated from the model. And if you did, some types of simple optimizers may fail. You should look for a rootfinding algorithm if you have as many data points as parameters.
- It may be that your model is not appropriate, so you will never be able to match the "shape". Do you know indepedently that your proposed model should work (your data is very clean...was it generated from a model?)
- I'm not sure if this will help, but can you combine the offsets a-c into a 5th parameter f:

Onkar Khadke
on 29 Oct 2020
Alex Sha
on 29 Oct 2020
Hi, Onkar, your data and equation are fit good enough as below:
Root of Mean Square Error (RMSE): 0.000583470511926158
Sum of Squared Residual: 0.000230476416520552
Correlation Coef. (R): 0.999845492636139
R-Square: 0.999691009144803
Adjusted R-Square: 0.999690092257993
Parameter Best Estimate
---------- -------------
a -0.00124853917372643
b -0.0803208242522166
c 1.51360739455312E-14
d 0.506966190396915

Onkar Khadke
on 29 Oct 2020
Alex Sha
on 30 Oct 2020
Hi, Onkar, the result is obtained by a software named 1stOpt, guessing of initial start-values is not required anymore by end-users, maybe because this software emploies an unique global optimization algorithm. There is also a Global Optimization toolbox in Matlab, theoretically, global optimization algorithms are not dependent on initial start-values, however, the results from Global Optimization toolbox in Matlab have still a considerable gap compared with 1stOpt.
Onkar Khadke
on 30 Oct 2020
Alex Sha
on 30 Oct 2020
You are welcome. Actually, there is one more solution (the two sets of results seem to be symmetrical):
Root of Mean Square Error (RMSE): 0.000583470511925808
Sum of Squared Residual: 0.000230476416520275
Correlation Coef. (R): 0.999845492596033
R-Square: 0.999691009064604
Adjusted R-Square: 0.999690092177556
Parameter Best Estimate
---------- -------------
a -1.51369467033431E-14
b -0.50696517676424
c 0.00124854020427691
d 0.0803208040636604
Onkar Khadke
on 30 Oct 2020
Onkar Khadke
on 5 Nov 2020
Alex Sha
on 6 Nov 2020
Hi, postout your data and fitting equation here, I will try for you
Onkar Khadke
on 6 Nov 2020
Alex Sha
on 10 Nov 2020
Hi, Onkar, the amount of data for 180_Nimon is very large, take too much time, so I evenly extract one-thousandth of data points, you can take the results from 1stOpt as the initial start-values and do again in Matlab for all your data.
180_Nimon:
Root of Mean Square Error (RMSE): 0.000767578707146424
Sum of Squared Residual: 0.0639068586093132
Correlation Coef. (R): 0.997544863719544
R-Square: 0.995095755133243
Adjusted R-Square: 0.995095664703245
Parameter Best Estimate
---------- -------------
a 0.216233837855244
b -0.0036792514520028
c 0.216554776487748
d 0.00367854558388458

300_Nimon (All data):
Root of Mean Square Error (RMSE): 0.00125060834729753
Sum of Squared Residual: 0.00395697373297554
Correlation Coef. (R): 0.998488831980626
R-Square: 0.996979947590035
Parameter Best Estimate
---------- -------------
a 0.0563668259802289
b -0.0117549539832182
c 0.0129130829009419
d 0.0549829731742771

350_Nimon(All data):
Root of Mean Square Error (RMSE): 0.00161465848055046
Sum of Squared Residual: 0.00219519673142098
Correlation Coef. (R): 0.999142995467777
R-Square: 0.998286725392322
Parameter Best Estimate
---------- -------------
a -0.0261576770771583
b -0.143454016006819
c 0.0425407232155395
d -0.114127486555251

Onkar Khadke
on 11 Nov 2020
Alex Sha
on 11 Nov 2020
Pleasure, you are welcome!
Accepted Answer
More Answers (0)
Categories
Find more on Linear and Nonlinear Regression in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!