curve fitting tool custom equation
33 次查看(过去 30 天)
显示 更早的评论
Hi,
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!
3 个评论
Sam Chak
2022-4-18
编辑:Sam Chak
2022-4-18
Can you provide the data t and h?
Technically, if , then , but since your equation was incorrect, it didn't fit.
The signal seems to slow down significantly in these 3 cycles, but regains momentum after 5.6 seconds.
The signal doesn't look like the one produced from a 2nd-order linear system. So your proposed model won't work. A rough estimation shows it could be from a 4th-order system.
采纳的回答
John D'Errico
2022-4-18
编辑:John D'Errico
2022-4-18
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.
2 个评论
Sam Chak
2022-4-19
From your Book1 data, the output signal is quite large and appears to be some kind of a delayed signal. Thus, I rescaled and restructured for better fitting.
minh = min(h);
t1 = t/1e7;
h1 = h/abs(minh);
v = find(abs(t1) < 0.7);
[~, idx] = min(h1)
t2 = t1(idx:length(v)+1,:);
h2 = h1(idx:length(v)+1,:);
If you insist to use your teacher's suggested model:
then
Since the displacement d is known, the amplitude a can be determined.
With the shifted center is known, you need to determine only two parameters:
, .
If you consider the phase shift in the cosine wave, then above assumptions are invalid.
更多回答(2 个)
Alex Sha
2022-4-19
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
R-Square: 0.940401357853383
Adjusted R-Square: 0.939783755344092
Determination Coef. (DC): 0.940401357853381
Chi-Square: -43481.4424771284
F-Statistic: 753.442740102336
Parameter Best Estimate
---------- -------------
a -291924.957940865
b 7.9210511350074E-7
c -1.68465029667797E-5
d -2953.68909153569
e -9546.50019773865
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!