필터 지우기
필터 지우기

Fit returns Imaginary Coefficients

조회 수: 12 (최근 30일)
Chris
Chris 2013년 3월 20일
댓글: Matt J 2022년 4월 24일
I am fitting a complex function to complex data, but the coefficients must be real. However, when fitting I get complex valued coefficients. Most of the time its fine, because the complex part is several orders of magnitude smaller than the real part, but sometimes beta(1) has a complex part that is of the same order of magnitude as the real part. I have tried using both nlinfit and lsqcurvefit. What fitting function and options can I use to force the coefficients to stay real? I cannot just ignore the complex data because it is important, and I cannot fit the imaginary and real data separately because the coefficients must be the same for the real and imaginary part.
F = @(beta,k) beta(1)*beta(2)*exp(-beta(2)^2/2*(k - beta(3)).^2 - 1i*beta(4)*(beta(3) - k))
  댓글 수: 2
Matt J
Matt J 2013년 3월 20일
편집: Matt J 2013년 3월 20일
You haven't mentioned what code you're using to perform the fit.
Chris
Chris 2013년 3월 20일
I have tried nlinfit and lsqcurvefit. Both yield the same result.

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

답변 (2개)

Matt J
Matt J 2013년 3월 20일
편집: Matt J 2013년 3월 20일
Change F to
model= @(beta,k) beta(1)*beta(2)*exp(-beta(2)^2/2*(k - beta(3)).^2 - 1i*beta(4)*(beta(3) - k))
F=@(beta,k) [real(model(beta,k)); imag(model(beta,k))];
and split your ydata into real and imaginary parts similarly.
  댓글 수: 2
Chris
Chris 2013년 3월 21일
and then just fit the real part?
Matt J
Matt J 2013년 3월 21일
편집: Matt J 2013년 3월 21일
No, as you can see from my modification of F, the imaginary part is included as well
imag(model(beta,k))

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


Miranda Jackson
Miranda Jackson 2022년 4월 23일
Use real() on all the coefficients in the fitting function so the imaginary part won't have any effect on the solution. Then use real() on the resulting coefficients you get from lsqcurvefit. Even if the coefficients go complex, only the real part will affect the result of the fit.
  댓글 수: 1
Matt J
Matt J 2022년 4월 24일
Note that with this approach, you will not be able to apply bounds on the coefficients.

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

카테고리

Help CenterFile Exchange에서 Least Squares에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by