Asked by Lewis Brammeld
on 14 Feb 2019

Hi, my brain is pickled with this one. Below are the two graphs I have plotted with exp2 function. The points do not match the curve, and this is ultimately changing my entire answer, as it is giving the wrong values out, and I cannot understand why?

Here is the code I am using, both graphs plot a concentration against time, but yet give different results:

CH4_fit = fit(Res_time, CH4_exp, 'exp2');

CH4_coeff = coeffvalues(CH4_fit); %Co-efficient values for exponential fitting

CH4_pred =(CH4_coeff(1)*exp(CH4_coeff(2)*Res_time)) + ...

(CH4_coeff(3)*exp(CH4_coeff(4)*Res_time));

plot(Res_time,CH4_exp, Res_time, CH4_pred);

Can I just added that the exact same data was run on different computers, and it gave the same equation co-efficients exactly (to 4.dp) and the same times, but yet still outputs different concentrations on my version? I have the R2018b, and I have just used default settings (don't know how to change anything, so I definitely haven't).

Answer by John D'Errico
on 14 Feb 2019

Edited by John D'Errico
on 14 Feb 2019

Accepted Answer

Where should I start? :-)

A terribly important feature of ANY exponential model is you absolutely, positively need good start points.

Asecond important thing is you need good data. Here, you have crappy data. (Sorry, but that is a tough model to fit well, because sums of exponentials are difficult to fit.) So better data would really help.

mdl = fit(x,y,ft,'start',[.05 350 .05 30])

mdl =

General model:

mdl(x) = a*exp(-b*x) + c*exp(-d*x)

Coefficients (with 95% confidence bounds):

a = 0.05937 (0.04962, 0.06911)

b = 368.4 (279.8, 457)

c = 0.01068 (0.0009941, 0.02036)

d = 61.21 (12.76, 109.7)

plot(mdl)

hold on

plot(x,y,'bo')

As exponential fits go, not terrible. I had to spend a few minutes to find good starting values for the parameters. If you did not do that, letting fit choose starting values for you? You would then expect complete crap for a result.

Again, the most important thing is to remember that exponential models NEED good starting values, especially for the rate parameters.

Lewis Brammeld
on 14 Feb 2019

John D'Errico
on 14 Feb 2019

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 7 Comments

## David Goodmanson (view profile)

Direct link to this comment:https://de.mathworks.com/matlabcentral/answers/445046-exponential-fitting-function-not-plotting-the-same-information-as-the-data-points#comment_671467

## Lewis Brammeld (view profile)

Direct link to this comment:https://de.mathworks.com/matlabcentral/answers/445046-exponential-fitting-function-not-plotting-the-same-information-as-the-data-points#comment_671471

## David Goodmanson (view profile)

Direct link to this comment:https://de.mathworks.com/matlabcentral/answers/445046-exponential-fitting-function-not-plotting-the-same-information-as-the-data-points#comment_671474

## Lewis Brammeld (view profile)

Direct link to this comment:https://de.mathworks.com/matlabcentral/answers/445046-exponential-fitting-function-not-plotting-the-same-information-as-the-data-points#comment_671475

## David Goodmanson (view profile)

Direct link to this comment:https://de.mathworks.com/matlabcentral/answers/445046-exponential-fitting-function-not-plotting-the-same-information-as-the-data-points#comment_671478

## John D'Errico (view profile)

Direct link to this comment:https://de.mathworks.com/matlabcentral/answers/445046-exponential-fitting-function-not-plotting-the-same-information-as-the-data-points#comment_671481

## Lewis Brammeld (view profile)

Direct link to this comment:https://de.mathworks.com/matlabcentral/answers/445046-exponential-fitting-function-not-plotting-the-same-information-as-the-data-points#comment_671484

Sign in to comment.