fminsearch for complex input for curve fitting

10 ビュー (過去 30 日間)
VISWANATH
VISWANATH 2014 年 10 月 23 日
回答済み: VISWANATH 2014 年 10 月 29 日
Dear all, I would like to fit experimental data with custom equations. I aim for the best fit of the theoretical curve to the experimental data by minimizing the residuals and use fminsearch to find minimal error.
The attached code works well for the real inputs
[R, fval] = fminsearch(err, 2.11)% finds the minimum of err But it fails for the
[R, fval] = fminsearch(err, 2.0-0.064i)
Help for fminsearch suggests to input split into real, imaginary parts and work to obtain the best fit. I have a little idea of doing this.
Could somebody help me with this problem? Thanks all.
  1 件のコメント
VISWANATH
VISWANATH 2014 年 10 月 28 日
I used
% Absolute error err = @ (n1) sum((abs(Rtot_s(n1)).^2 - S).^2 + (abs(Rtot_p(n1)).^2 - P).^2) % Minimum search for the error value x0 = complex(2.1,-0.07) [R, fval, exitflag] = lsqnonlin(@(x)err(x), real(x0),imag(x0) )
O/p R =
2.1084
fval =
28.0003
exitflag =
5.2915

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

回答 (2 件)

Matt J
Matt J 2014 年 10 月 23 日
編集済み: Matt J 2014 年 10 月 23 日
Assuming your err function is real-valued,
[R, fval] = fminsearch(@(x) err( complex( x(1),x(2) ) ), [2.0,0.064])
  4 件のコメント
VISWANATH
VISWANATH 2014 年 10 月 28 日
When i used
[R, fval, exitflag] = lsqnonlin(@(x)err(x),complex(2.11,-0.064) )
gave the best values for fit but solution did not converge!!! Where do you think i am going wrong?
R =
2.1151 - 0.0640i
fval =
1.6100e-04
exitflag =
0.0127
Matt J
Matt J 2014 年 10 月 28 日
The objective function must be a mapping from reals to reals. The initial guess x0 must also be real. So, complex(2.11,-0.064) is not legal as an initial point.

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


VISWANATH
VISWANATH 2014 年 10 月 29 日
Hi Matt, It looks like the following example may help me to solve my problem. If you have any suggestions i would be glad to hear from you. Thanks a lot. Fit a Model to Complex-Valued Data

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by