nonlinear fit with function a*exp((q1+​i*q2)*x)/s​qrt(x)

조회 수: 2 (최근 30일)
Jiong Yang
Jiong Yang 2021년 5월 7일
댓글: Jiong Yang 2021년 5월 10일
I am trying to do a nonlinear fit of the attached data, which is the blue decaying sine or cosine wave in the attached image.
I want to fit the data into the function of a*exp((q1+i*q2)*x)/sqrt(x), where a, q1 and q2 are real numbers.
I have tried to use lsqnonlin, but could not limit those three fitting variables to be real. And the fitted results do not make sense.
Any help will be much appreciated.
  댓글 수: 5
Alex Sha
Alex Sha 2021년 5월 10일
Hi, if you want both of q1 and a2 to be positive, the results below may be you want:
Root of Mean Square Error (RMSE): 4.84330718082384E-7
Sum of Squared Residual: 3.30752504714258E-11
Correlation Coef. (R): 0.822474332455383
R-Square: 0.676464027547928
Parameter Best Estimate
-------------------- -------------
a 1.35682343774127E-9
q1 9.79296293081736E-11
q2 13826159.1347865
Jiong Yang
Jiong Yang 2021년 5월 10일
Thank you, Alex. Problem solved already.

댓글을 달려면 로그인하십시오.

채택된 답변

Bjorn Gustavsson
Bjorn Gustavsson 2021년 5월 7일
This seems like you need to take a standard step from the physicsist's complex representation (which admittedly we often use a bit carelessly as a very convenient(!) shorthand). My guess is that you need to do something like this:
% your model-function: the real part of a modified damped oscillating
% exponential:
curve_fcn = @(pars,x) real((pars(1)+1i*pars(2))*exp((pars(3)+1i*pars(4))*x)./sqrt(x));
err_fcn = @(pars,x,y,fcn) sum((y-fcn(pars,x)).^2);
par0 = [-0.1378e-8, -0.0541e-8, 4.1643e+03, 2.3100e7]; % this might have to be adjusted to get a good enough start-guess
parBest = fminsearch(@(pars) err_fcn(pars,x,y,curve_fcn),par0);
subplot(2,1,1)
plot(x,y,x,curve_fcn(parBest,x))
subplot(2,1,2)
plot(x,y-curve_fcn(parBest,x))
You might have to iterate the optimization-step with the parameter estimate parBest as the new input for par0 to get a improved fits.
You might consider a properly weighted sum-of-square optimization instead of the straight-forward sum-of-squares, but in order to do that you'll need estimates of the uncertainties (standard-deviation) of each measurement point.
HTH
  댓글 수: 3
Bjorn Gustavsson
Bjorn Gustavsson 2021년 5월 10일
You must have made a typo somewhere, if both q1 and q2 should be positive you'll have a growing exponential factor - while it seems your signal decays. After a couple of re-runs I got the best fitting parameters:
parBest = [0.1744e-8 0.2007e-8, -3.5048e+05, 1.3371e+07];
That fit might be close to the best to this data for this model-function. The double-peak at the end indicates that the data is more complicated than that simple function can produce. Exactly how or what is "a very difficult question". More data is required to do this experimentally, or a far more thorough modeling derivation has to be made.
The reason for using two components for the amplitude is that you have a small phase-shift of the oscillating part relative to x=0. To fit for that you need a model for that.
HTH
Jiong Yang
Jiong Yang 2021년 5월 10일
It really helps. Thank you very much!
Now I have a almost perfect fit for the first 4 peaks. I am not too worried about the double peak at the end, as the data is the inverse fourier transform of the fourier transform of the original data.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by