curve fitting tool custom equation
7 views (last 30 days)
Michal Naim Ben Eliyahu on 18 Apr 2022
I used cf tool to get a function to describe my data but it seems to give me a straight line.
I know the custom equation is the right one is there anything else I can do to make the function more like my data?
Thank you all for your time!
John D'Errico on 18 Apr 2022
Edited: John D'Errico on 18 Apr 2022
A general problem with the curve fitting toolbox is that it does not understand the mathematics of a model you pose to it. Not that this is truly a fixable problem. It is not, at least not until computers get far more intelligent than they are now. And I sort of fear that day anyway. :) But many users do not understand what has happened in a fit, and why they get a poor fit.
The curve fitting toolbox is just a search tool, that looks for good sets of parameters. But if it starts the search in a bad place, it gets lost. And I don't have your data, so I cannot easily show how to fit it.
@Torsten is totally correct, of course, that the data out past roughly t=7 is actively useless in the fit. Worse, it can cause some subtle problems. So toss that part.
But as I said, the biggest problem here is poor starting values. But there is also probably a lack of fit problem. That model is not perfect, would be my guess, because the initial transient seems to be larger than I would expect for an exponential decay. Again, lacking your data, it is hard to tell.
What are good starting values? e is the long term average behavior. from your plot, e should be around -11.
b is the exponential decay constant. It tells how fast the exponential drops off. You can guess that value from seeing the decay of each peak in the curve. As a wild guess from your plot, b might be around 0.3.
However, the most important parameter in this curve is the value of c. If you get that number wrong by as much as a factor of 2 too large or too small, your model will likely fit very poorly. A cosine curve goes through one period in a span of 2*pi. But from your plot, I can see roughly 5.5 oscillations in the interval from 4 to 6. That would suggest c should be approximately
c0 = 2*pi/(6 - 4)*5.5
fplot(@(t) cos(c0*t),[4 6])
So a good starting value for c would be roughly 17. As you can see from my plot, 5.5 periods in the span from 4 to 6, with that value for c.
a+e is the y-intercept of the curve at t==0. But we don't see any data near t==0. Luckily, the fit will tend to be insensitive to errors in your initial estimate of a and d. I don't even know the sign if a. But the magnitude of a should be roughly 4.
Again, without any real data, all of the above are just educated guesses.
The problem is, the curve fitting toolbox does not understand that it needs better startign values than just random numbers as start points. And if you get that initial estimate for c off by a factor of as much as 2, things will fit poorly.
When all is said and done however, my bet is the curve will fit poorly near the initial transient, since those peaks do not seem to behave as a truly exponential decay would. Again, that is just a guess. If you want better help in fitting that data, I would need to have the data itself.
More Answers (2)
Alex Sha on 19 Apr 2022
if taking only part of data, for example, from No. 105 to No. 300, then the result will looks good
Sum Squared Error (SSE): 1111312565.89975
Root of Mean Square Error (RMSE): 2381.16821558602
Correlation Coef. (R): 0.969742933902271
Adjusted R-Square: 0.939783755344092
Determination Coef. (DC): 0.940401357853381
Parameter Best Estimate