problem with lsqcurvefit: initial values are not updated

4 views (last 30 days)
Hi,
I'm trying to perform some data fitting using the following function:
function F = myfun(x,xdata)
%fitting parameters
m = x(1);
g = x(2);
tu = x(3);
td = x(4);
%some constants
T = 0.145;
nc = 2.09e11;
hb = 6.582e-16;
mb = 5.788e-5;
kb = 8.617e-5;
ej = 1.60218e-19;
me = 9.10994e-31;
e = 1.60218e-19;
%
%Define some variables
Ef = (hb*hb*2*pi*nc*1e4/(2*m*me))*ej;
wc = e.*xdata./(m*me);
hw = hb.*wc;
QX = 2.*pi.*pi.*kb.*T./hw;
Ez = g.*mb.*xdata./2;
F = 0.*xdata;
%strart the loop
for i=1:5
A = (2.*i.*QX)./sinh(i.*QX);
B = exp(-i.*pi./(wc.*tu));
C = exp(-i.*pi./(wc.*td));
PHI_U = (2.*pi.*i.*Ef./hw).*(1.+(Ez./Ef))-(pi.*i);
PHI_D = (2.*pi.*i.*Ef./hw).*(1.-(Ez./Ef))-(pi.*i);
F = F + A.*(B.*cos(PHI_U)+C.*cos(PHI_D)).*30;
end
end
When I run the lsqcurvefit using the initial values x0:
[x,resnorm] = lsqcurvefit(@myfun,x0,xdata,ydata)
the fitting seems to start normally, but at the end, nothing is updated. The output values (x) are exactly same as the initial values (x0). I tried to fix this problem by changing the tolerance options, but to no avail! Nothing has so far worked.
Any suggestion/workaround is highly appreciated.

Answers (2)

Star Strider
Star Strider on 2 Jul 2015
That usually occurs if your initial parameter estimates are either exactly correct or very far off. I would use an optimoptions options structure to see the process, perhaps:
opts = optimoptions('lsqcurvefit', 'Diagnostics','on', 'Display','iter-detailed');
then add it to your lsqcurvefit call. Experiment with these to find the ones that are most helpful in tracking what lsqcurvefit is doing.
  1 Comment
Star Strider
Star Strider on 3 Jul 2015
My pleasure.
I don’t know what your data are, but your ‘B’ and ‘C’ variables are complex exponentials, so ‘F’ is likely also complex. That could be very difficult to fit, even to complex data.
If you know more accurate initial estimates for your parameters, use them. Otherwise, if you have the Global Optimization Toolbox, consider using a genetic algorithm, pattern search, or another routine to estimate your parameters, then use lsqcurvefit to fit them precisely.

Sign in to comment.


Saeed
Saeed on 3 Jul 2015
Thanks star strider for your suggestion.
Actually my initial values are neither correct not that far off. Anyway, I tried the options you suggested and ran lsqcurvefit as follows:
>> [x,resnorm] = lsqcurvefit(@myfun,x0,xdata,ydata,[],[],opts)
As you can see, I set the lower and upper bounds undefined. Below is the diagnosis report:
____________________________________________________________
Diagnostic Information
Number of variables: 4
Functions
Objective: lsqcurvefit/objective
Gradient: finite-differencing
Number of lower bound constraints: 0
Number of upper bound constraints: 0
Algorithm selected
trust-region-reflective
____________________________________________________________
End diagnostic information
Norm of First-order
Iteration Func-count f(x) step optimality
0 5 1.66698e+06 1.21e+14
1 10 1.66698e+06 4.59704e-09 1.21e+14
2 15 1.66698e+06 4.59704e-09 1.21e+14
Optimization stopped because the norm of the current step, 4.597035e-09,
is less than options.TolX = 1.000000e-06.
Optimization Metric Options
norm(step) = 4.60e-09 TolX = 1e-06 (default)
x =
0.2000
3.9000
0.0000
0.0000
resnorm =
1.6670e+06
Any suggestion what to do next?

Community Treasure Hunt

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

Start Hunting!