Damped Harmonic Oscillator fitting for data set
古いコメントを表示
Hello, I am working on a Avdanced Lab fit of a damped harmonic oscilator. I am trying to use this code from the forum but I can not seem to get it to work. The code I am using is attached. The x data is time in seconds and the y data is the position.
Here is what the plot is coming out as.
Thank you so much,
Sofia

回答 (1 件)
I think it pretty much depends on the custom nonlinear model that you supply to the fit() algorithm, as well as the lower and upper boundaries of the coefficients.
This may not the best fitted curve, but at least it shows something.
fo = fitoptions('Method', 'NonlinearLeastSquares', ...
'Lower', [0, 0, 0, 0, 0, 91], ...
'Upper', [10, 1, 0.01, 0.1, 0.001, 94], ...
'StartPoint', [5 0.5 0.005 0.05 0.0005 92.5]);
ft = fittype('d - a1*exp(-b1*x)*cos(b2*x) - a2*exp(-b1*x)*sin(b2*x) + c*x', 'options', fo);
[curve, gof] = fit(x, y, ft)
curve =
General model:
curve(x) = d - a1*exp(-b1*x)*cos(b2*x) - a2*exp(-b1*x)*sin(b2*x) + c*x
Coefficients (with 95% confidence bounds):
a1 = 3.629 (3.57, 3.688)
a2 = 0.481 (0.4195, 0.5426)
b1 = 0.001029 (0.0009959, 0.001063)
b2 = 0.022 (0.02197, 0.02204)
c = 0.0002824 (0.0002621, 0.0003027)
d = 92.47 (92.44, 92.5)
gof =
struct with fields:
sse: 4.5976
rsquare: 0.9919
dfe: 255
adjrsquare: 0.9918
rmse: 0.1343
Result:

カテゴリ
ヘルプ センター および 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!