What does this error mean? (lsqcurvefit)

I have no idea what line291 is saying here. Seems pretty much advanced stuff. It came up when I was trying running a bunch of lsqcurve fit using Trust region algorithm (due to lb and ub, otherwise would have preferred Levenberg algorithm). I am iterating my input parameters myself too via for loop, as it seemed that iniital parameters were affecting final outcome too much just to see where it goes. and give best solution. But after 5 mins this came up.
Error using trdog>quad1d (line 291)
Square root error in trdog/quad1d.
Error in trdog (line 180)
[nss,tau] = quad1d(nss,ssssave,delta);
Error in snls (line 316)
[sx,snod,qp,posdef,pcgit,Z] = trdog(x,g,A,D,delta,dv,...
Error in lsqncommon (line 150)
[xC,FVAL,LAMBDA,JACOB,EXITFLAG,OUTPUT,msgData]=...
Error in lsqcurvefit (line 253)
[xCurrent,Resnorm,FVAL,EXITFLAG,OUTPUT,LAMBDA,JACOB] = ...
Error in lambda7 (line 211)
[phiLSQ,resnorm,fval,output]= lsqcurvefit( @(phi,x) lambdafn7(phi,x),initial_param,x,y,lb,ub,options);

1 Comment

‘What does this error mean?’
We have no idea. We don’t have your code to refer to.

Sign in to comment.

 Accepted Answer

I'd venture it got into a negative parameter region and hence got an imaginary value from a square root that was trapped by the internal routine quad1d. Well, let's just look and see...
Indeed,
function[nx,tau] = quad1d(x,ss,delta)
%QUAD1D 1D quadratic zero finder for trust region step
% [nx,tau] = quad1d(x,ss,delta) tau is min(1,step-to-zero)
% of a 1-D quadratic ay^2 + b*y + c.
...
% Algorithm:
% numer = -(b + sign(b)*sqrt(b^2-4*a*c));
% root1 = numer/(2*a);
% root2 = c/(a*root1); % because root2*root1 = (c/a);
...
numer = -(b + sign(b)*sqrt(b^2-4*a*c));
r1 = numer/(2*a);
r2 = c/(a*r1);
tau = max(r1,r2);
tau = min(1,tau);
if tau <= 0,
error(message('optimlib:trdog:SqrRt'));
end
nx = tau*x;
So indeed that's the cause. As Star says, not much we can say other than that w/o actual code and data to go with it but looks like your modifications didn't help in this case, anyway. What if you remove those?

5 Comments

Vipultomar
Vipultomar on 15 Jan 2017
Edited: Vipultomar on 15 Jan 2017
okay. Thanks for the input. I understand not much can be said without actual data and code. How do I share the code? Btw which part did you want me to remove?
Based on his other threads, Vipultomar is working on an eigenvalue fitting problem. I suspect the error comes about because the matrix being analyzed is not symmetric and therefore the eigenvalue is not always real.
When I click at the error line it redirects me to "TRDOG Reflected (2-D) trust region trial step " this function file, which I believe is related to trust region algorithm. After pointlessly going through the code (which is too much for me to understand at this point) I think there is something wrong with my input parameters, which are giving some eigenvalues (output of my function) in such a way that the minimization algorithm is not able to process. So I am looking at my input parameters code now. In fact found something wrong there. Will update here if I find the culprit.
"Btw which part did you want me to remove?"
The part that is related to ..." I am iterating my input parameters myself too". Wondered if that were buggering up things.
Yes. That was the actual problem. As I am playing around with 10 independent parameters, it seemed very tedious and unsystematic to change them manually for initial guess. Which is why I am changing those parameters in systematic way near my expected solution. As there were multiple (nested) for loops, things got bit messy in the end, resulting in unexpected values of intial parameters. Now I have sorted them out and it is running fine. Thanks for help.

Sign in to comment.

More Answers (1)

satya kothapalli
satya kothapalli on 18 Jan 2018
Edited: Walter Roberson on 18 Jan 2018
HI Vipul,
I also facing the same problem with my model code, as you have described in the first comment. It is interesting that you have sorted out multiple loops and identified the unexpected initial parameters in the end. Can you describe exactly what changes you have made to run smoothly. It would help me a lot.
Thank you, Regards, Satya.

Asked:

on 15 Jan 2017

Edited:

on 18 Jan 2018

Community Treasure Hunt

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

Start Hunting!