Fsolve cannot solve problem but Kaleidagraph can!

조회 수: 1 (최근 30일)
Christopher Lundgren
Christopher Lundgren 2015년 8월 19일
편집: Matt J 2015년 8월 19일
Hi,
I'm trying to minimize the following function in th least-square sense with respect to some experimental data.
function F = myS21(X0,H,t,f)
mu_0 = 4*pi*1e-7;
mu_B = 9.27400968e-24;
g = 2;
h = 6.62606957e-34;
H = H(1:length(H)/2);
H_eff = f*h/(g*mu_0*mu_B);
S21 = X0(1)*exp(1i*X0(2)) + X0(3)*exp(1i*X0(4))*t - ...
1/(X0(5)*exp(1i*X0(6))) * (X0(7)*(H-X0(7))) ./ ...
( (H-X0(7)).^2 - H_eff^2 - .5*1i*X0(8)*(H-X0(7)) );
F = [real(S21); imag(S21)];
##########################
So S21_10 are the complex experimental data and do this in an interval I call limits10 (since the expression is is only valid somewhere around this neighborhood). Finally I do the curve fit using:
options = optimset('Display','iter','Algorithm','levenberg-marquardt',...
'TolX',eps,'TolFun',eps,...
'MaxFunEvals',1e5,'MaxIter',1e4);
[x fval eflag] = fsolve(@(x) norm(myS21(X0,...
[H(limits10); H(limits10)],t(limits10),f) - ...
[real(S21_10(limits10)); imag(S21_10(limits10))]),X0,...
options);
The problem is that fsolve refuses to take even one iteration even when my initial guesses are quite close (it stops with exitflag -2). As a contrast, Kaleidagraph finds the correct minimum with complete crap initial guesses. How can I tweak fsolve to take more steps, and ideally find a good minimum?
  댓글 수: 2
Torsten
Torsten 2015년 8월 19일
You return a scalar to fsolve, whereas it expects a vector of length 16 (=2*8).
Furthermore, in your function definition for fsolve (@(x)norm ...) you don't address the argument x fsolve supplies.
For curve fitting or similar problems, don't use fsolve - use lsqcurvefit or lsqnonlin.
Best wishes
Torsten.
Christopher Lundgren
Christopher Lundgren 2015년 8월 19일
Thanks, this seems to have solved my problem!

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Solver 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