How to fit a custom equation?

madhuri dubey (view profile)

on 9 Jul 2018
Latest activity Answered by Image Analyst

Image Analyst (view profile)

on 11 Jul 2018
Accepted Answer by Star Strider

Star Strider (view profile)

My equation is y=a(1-exp(-b(c+x)) x=[0,80,100,120,150] y=[2195,4265,4824,5143.5,5329] When I am solving it in matlab, I am not getting a proper fit in addition, sse=6.5196e+05 and r square=0.899. Although the r square value is acceptable, the sse is too high. Therefore kindly help to get minimum sse. Further I have tried in curve fitting tool but I got same thing.

Star Strider

Star Strider (view profile)

님의 답변 9 Jul 2018
채택된 답변

I get good results with this:
yf = @(b,x) b(1).*(1-exp(-b(2)*(b(3)+x)));
B0 = [5000; 0.01; 10];
[Bm,normresm] = fminsearch(@(b) norm(y - yf(b,x)), B0);
SSE = sum((y - yf(Bm,x)).^2)
Bm =
6677.76372320411
0.0084077646869843
47.1622210493944
normresm =
195.173589996072
SSE =
38092.7302319547

Star Strider

Star Strider (view profile)

10 Jul 2018
As always, my pleasure.
I would be tempted to use polyfit to get initial estimates of ‘a’, ‘c’, and ‘d’ (estimated as [-0.09, 34, 2200] when I did it) , then let your nonlinear parameter estimation routine (similar to my code) estimate them and ‘b’ (that I would initially estimate as 10).
I usually create my own initial population for ga. I would be tempted here to use a matrix of 500 individuals, defined as:
init_pop = randi(5000, 500, 4);
using the appropriate options function (linked to in the See Also section in the ga documentation) to define it as such. The ga function is efficient, however since it has to search the entire parameter space, it will take time for it to converge.
Note that you have 5 data pairs and you are now estimating 4 parameters.

madhuri dubey (view profile)

11 Jul 2018
When I use polyfit to get initial estimates of ‘a’, ‘c’, and ‘d’ , I got [-0.0001, 0.0346, 2.1807]. Why there is difference in constant values for the same data.
Star Strider

Star Strider (view profile)

11 Jul 2018
There isn’t. You’re ignoring the constant multiplication factor 1.0E+03. The full result:
p =
1.0e+03 *
-0.000088159928538 0.034559355475118 2.180742845451099

Image Analyst

Image Analyst (view profile)

님의 답변 11 Jul 2018

For what it's worth, I used fitnlm() (Fit a non-linear model) because that's the function I'm more familiar with. You can see it gives the same results as Star's method in the image below. I'm attaching the full demo to determine the coefficients and plot the figure. 