Custom equation in curve fitting

So i was trying to modify the customized equation in curve fitting tool but apparently it didn't work. This picture below is the fit I'm trying to modify....my equation is a*exp(b*(x-0.4))+c*exp(d*x)....the b,c,d, values are correct but a is not.
But when I tried to enter it as a custom equation
it gave me a straight line. I don't know what to do to fix that. Thanks

Answers (2)

Walter Roberson
Walter Roberson on 13 Jun 2018
Can you attach your data? For that matter, we are still waiting to see your data for https://www.mathworks.com/matlabcentral/answers/404992-curve-fit-exactly-the-function-i-enter
Notice that all of the coefficients cross 0, and are all of the form (-V, V) . That tells you that the model the fit was about equally as good with negative coefficients as with positive coefficients.
When you see large negative coefficients being used within exp() then what it tells you is that the fit was trying to drive the associated term to 0. That can happen if you used a starting point that happened to be outside the basin of attraction of the good solutions: the fit starts to head towards the asymptopes of a bad solution.
When I look at your graph, it seems to me that you should be trying with x+1 or so rather than x-0.4
See https://www.mathworks.com/matlabcentral/answers/403639-exponential-fit-not-working#answer_322886 for how I dealt with this same curve shape for someone else recently.

4 Comments

The data is attached. The 0.4 is the number I derived from the theoretical equation so it has to stay 0.4 to get the right answer.
There are competing models, both of which fit the data to pretty much noise level (fitting against the 6th decimal place)
a*exp(b*(x-0.4)) + c*exp(d*x)
167472.52886263 17.9139496320039 -1 -19.4716843748638
The residue on the above is on the order of 1E-14, but the first component of it (the a) has a large uncertainty, with quite different a values having residues of the same order of magnitude. The -1 for the c component is near exact.
-0.00041440212052067 -19.4716843748638 129.41117752242 17.9139496437448
The residue on the above is on the order of 5E-13, but I did not optimize it for as long a time as the other one.
In both cases, at one end of the range (x = -1) one of the subexpressions is large and negative and the other subexpression is about 2E-6, and at the other end of the range (x = 0) one of the subexpressions is about 129.4 and the other is -1. But the two models differ as to which of the two subexpressions is which. In one of the two, the handling of the large range of B values is mostly handled by the first subexpression, and in the other model, the handling of the large range of B values is mostly handled by the second subexpression.
You effectively cannot tell the two models apart as far as fitting goes, unless perhaps you are willing to compute at high precision and willing to say that the readings stored in the data file have an unusually high accuracy.
You should not treat the above two models as exact coefficients, especially not the first parameter a of the first model.
is there any ways that I can modify the code so that the first coefficient is near 0.1? (which is the correct value)
An a coefficient close to 0.1 is not a good fit. You would get a marginally better fit from omitting either of the two terms, making it a single exponential instead of a sum of two exponentials -- that's how poor a fit using 0.1 is.
To get a good fit you need to have either large a values with c near -1, or else small a values with c near 129.

Sign in to comment.

serkantekbiren
serkantekbiren on 4 Dec 2019
How can you add a b c d coefficients of the graph?

3 Comments

Of which graph? Add them in what sense?
serkantekbiren
serkantekbiren on 4 Dec 2019
Edited: serkantekbiren on 4 Dec 2019
I am sorry. I am very new to matlab. That might have sounded like a stupid question. I have managed to plot my time based fouling rating data in curve fitting tool. Similar to what JuiChun Lin's pictures show, I have a similar custom equation used. However, I can not display the coefficients on the figure. Is there any way to display a,b,c and d coefficients on the figure ?
Are you relying on the plot from the Curve Fitting Tool, or are you doing your own plot() of the curvefitting object? If you are using the Curve Fitting Tool then we need to fight to find the (hidden) graphics objects of the tools, but if you are doing the plot() yourself then you would know the axes and would be able to text() or title() the coefficients into place.

Sign in to comment.

Categories

Tags

Asked:

on 13 Jun 2018

Commented:

on 4 Dec 2019

Community Treasure Hunt

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

Start Hunting!