I am getting a "Divide by zero" error when I set low tolerance values in LSQCURVEFIT. This happens when I run the following code:
function test() % test data
data = [10 5 2 1]; t = [1 2 3 4]; % initial guess
A0 = [10 1]; options = optimset('TolFun',1e-27,'TolX',1e-27, ... 'MaxIter', 5000,'MaxFunEvals',50000, 'display', 'iter'); A = lsqcurvefit(@myfunc,A0,t,data,[],[],options); % fitting function
function f = myfunc(A,t) f = A(1)*exp(-A(2)*t);
The exact error message is:
Warning: Divide by zero. > In optim\private\trust>seceqn at 128 In optim\private\trust>rfzero at 193 In optim\private\trust at 55 In optim\private\trdog at 228 In optim\private\snls at 393 In optim\private\lsqncommon at 213 In lsqcurvefit at 182 In test at 14
Best Answer