Identify rule that governs pattern in series.
이전 댓글 표시
I have a series of terms in a sequence and need to identify the rule that produces it. I know it is based on a damped harmonic oscillator but I am not sure which formula governs the interval. Here is the string, it is the interval rates in seconds: (108, 88, 92, 76, 80, 68, 64, 56, 40, 32, 8, 8) the closest I have come is: D_n = Asin(Bn + C)exp(-Dn) + E
A = Amplitude of the wave (could be around 28, as you noted that the sequence never went more than 28 in any direction) B = Frequency of the wave (which affects how “quickly” the wave oscillates - this could be tweaked to match the observed pattern) C = Phase shift of the wave (could potentially be 0 if the wave starts at its peak) D = Damping coefficient (this affects how quickly the oscillations decay - would need to be chosen to match the decay observed in the sequence) E = Equilibrium position (which would be 8, as the sequence oscillates around 8)
댓글 수: 7
Walter Roberson
2023년 7월 9일
That proposed function leads to poor results, at least if exp(-Dn) is understood as exp(-D*n)
John D'Errico
2023년 7월 9일
You don't have sufficient information to estimate (with any degree of confidence) those 5 parameters from that little data. You have only 12 data points, representing only a small fraction of one period of any oscillatory sequence.
Walter Roberson
2023년 7월 9일
편집: Walter Roberson
2023년 7월 9일
Your n is acting as the independent variable, with integer values. Now suppose you had a B0 for the sin(B*n+C) term. Let B=B0+k*2*pi for integer k. n*(B0+k*2*pi) = n*B0 + n*k*2*pi but n and k are integer and sin is periodic so that is the same as sin(n*B0+C). Therefore you should constrain B and C to one period of sin()
Just to add a little more detail to the excellent comments by @Walter Roberson and @John D'Errico, here is what happens when you do try to fit that function to your data:
% Your data
n = (1:12)'; % (I assume that this is implied.)
D_n = [108, 88, 92, 76, 80, 68, 64, 56, 40, 32, 8, 8]';
% Tabulate the data
tbl = table(n,D_n);
% Define function that will be used to fit data
% (F is a vector of fitting parameters)
f = @(F,n) F(1).*sin(F(2).*n + F(3)).*exp(F(4).*n) + F(5);
% Initial parameter guesses
beta0 = [1 1 0 1 0];
% Fit the model
mdl = fitnlm(tbl,f,beta0)
% Calculate the model values at the empirical x
D_n_predicted = predict(mdl,n);
% Plot the data and fit
figure
plot(n,D_n,'*',n,D_n_predicted,'g');
legend('data','fit')
There is lots going wrong here. Two big issues are
- The warning that some model parameters are not estimated well
- The errors ("SE" in the model output table) on the parameter estimates are huge compared to the estimates themselves, and the implications of that for their statistical significance
These both point to this being a terrible model (which John, Walter and I would simply know intuitively from experience), but is also borne out by the model fit.
Note that I might have been able to do a bit better with more precise initial parameter guesses. But that is a fool's errand. When you have a very small amount of data, you cannot (sensibly) fit a model that has many parameters.
You have not mentioned the purpose for this fit. Why are you doing it at all? What did you plan to do with the result? There may be a more sensible alternative.
And to expand on what @the cyclist just said, you have 5 unknowns in that model. But your data only has 12 data points, and over a VERY short region, if you want to estimate those parameters. But look at the data you show.
n = (1:12)'; % (I assume that this is implied.)
D_n = [108, 88, 92, 76, 80, 68, 64, 56, 40, 32, 8, 8]';
plot(n,D_n,'o')
And what I see is a LOT of noise. There is enough information in that data to estimate a straight line, but not really any more than that. Certainly NOT a damped sinusoid.
P1 = fit(n,D_n,'poly1')
plot(P1,n,D_n)
Is there a tiny amount of curvature in that data? Barely. So you might decide to fit a quadratic polynomial.
P2 = fit(n,D_n,'poly2')
plot(P2,n,D_n)
What I would look at in that fit, is how wide is the uncertainty in the quadratic coefficient. fit thinks it lies somewhere between -0.7897 and -0.02553. That is a pretty large interval. So anything more sophisticated than a simple quadratic is a silly thing to do with this data.
You ABSOLUTELY need better data, even if you belive this data lies on a damped sinusoid. AND you absolutely need MORE data, so over a longer period of time. In order to estimate that period AND a damping rate, you need at least a few periods from that curve.
Walter Roberson
2023년 7월 9일
Degree 9 polynomial looks decent R^2 when you center and scale, but any polynomial struggles with two adjacent values the same.
A 9th degree polynomial would be a literally insane fit. If it does fit well, that would be based merely on R^2. But R^2 does not measure what the curve does between the data points. And with 12 data points, and 10 parameters to estimate? It will be purely chasing noise. R^2 does not measure if the fit makes any sense at all.
n = (1:12)'; % (I assume that this is implied.)
D_n = [108, 88, 92, 76, 80, 68, 64, 56, 40, 32, 8, 8]';
nhat = (n - mean(n))/std(n);
P9 = fit(nhat,D_n,'poly9')
plot(P9,nhat,D_n,'o')
As I said, the degree 9 polynomials is a bad thing to do, even to bad data. Yes. It fits the data points reasonably well, but that is all one can say.
채택된 답변
추가 답변 (1개)
카테고리
도움말 센터 및 File Exchange에서 Chemistry에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!









