Is there any way to exclude the complex values ​​of the iterations with lsqnonlin ?

6 vues (au cours des 30 derniers jours)
I'm using lsqnonlin to solve a non linear system, and my solution must be real, so I wanted to know if I could exclude complex iterations so as to make more efficient the search.
Thanks in advance!

Réponse acceptée

Matt J
Matt J le 16 Sep 2014
Modifié(e) : Matt J le 16 Sep 2014
Just to be clear, the complex numbers are being introduced by the objective function that you have provided, not code elsewhere in lsqnonlin.
Make sure that your objective is not executing expressions like log(z) for negative z and similar things like that. If you have regions like that where the objective function is undefined, you should set the value there to NaN or Inf and you should probably use fmincon to do the optimization instead, with the sqp algorithm. The sqp algorithm has the capability of course-correcting when it strays into regions of NaNs or Infs in the objective or constraints.
  4 commentaires
Jurgen
Jurgen le 11 Nov 2014
Modifié(e) : Matt J le 12 Nov 2014
In my case I have a system of equations (without objective function), it enough to put zero in the part of the objective function?
fmincon(0,x0,[],[],[],[],lb,ub,nonlcon,options)
Matt J
Matt J le 12 Nov 2014
Modifié(e) : Matt J le 12 Nov 2014
I don't know why you would do that. If your equations have an exact solution, then using a least squares objective function should find it. However, you can also replace bad values returned by nonlcon with nans or infs in a similar manner.

Connectez-vous pour commenter.

Plus de réponses (1)

Jurgen
Jurgen le 15 Nov 2014
Modifié(e) : Jurgen le 15 Nov 2014
I'm a little confused now. Just to be clear, I need to solve a system containing non-linear equations and inequalities. Considering this I have two questions:
1) What is the best way to solve my system ?. I have tried lsqnonlin, Newton-Raphson and now I'm trying with fmincon.
2) Newton-Raphson and lsqnonlin solve it, but gives me complex numbers, which is useless for me.
Thanks a lot Matt!
  2 commentaires
Matt J
Matt J le 15 Nov 2014
Modifié(e) : Matt J le 15 Nov 2014
I don't see how you would have tried any of those. lsqnonlin doesn't handle nonlinear inequalities while Newton Raphson doesn't support inequality constraints of any kind.
Any of the fmincon formulations, using the sqp algorithm, that we were discussing should work, so long as a solution does indeed, exist. If an exact solution doesn't exist, you will have to compromise and accept a least squares solution. In that case, you need to decide which of your equations/inequalities need to be exactly satisfied and which you can relax.
Jurgen
Jurgen le 15 Nov 2014
Forget explain that. I use a gap, for example if I wanted X> Y, what I did was put Y-X + H = 0 with H greater than or equal to zero.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by