Fsolve cannot solve problem but Kaleidagraph can!

1 vue (au cours des 30 derniers jours)
Christopher Lundgren
Christopher Lundgren le 19 Août 2015
Modifié(e) : Matt J le 19 Août 2015
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 commentaires
Torsten
Torsten le 19 Août 2015
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 le 19 Août 2015
Thanks, this seems to have solved my problem!

Connectez-vous pour commenter.

Réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by