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

1 ビュー (過去 30 日間)
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 件のコメント表示非表示 4 件の古いコメント
Jiong Yang 2021 年 5 月 10 日
Thank you, Alex. Problem solved already.

サインインしてコメントする。

### 採用された回答

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 件のコメント表示非表示 2 件の古いコメント
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.

サインインしてコメントする。

### Community Treasure Hunt

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

Start Hunting!