How to constrain the optimized variable using fmincon ?

Hi everyone,
I am currently using fmincon function to solve an optimization problem.
Basically I am trying to minimize the integral (sum(abs)) of a variable u. The thing is that I want these u to always be >0, and I am not sure if what I do is correct or how to set correctly the constraint function "noncol" to create this condition.
Here it is what I am doing now: I compute the variable u in my costfun (then its integral), I put these u in global and put another global u in the noncol function to use it. I just set c=-u (as the c<0 and I want u>0). Is it correct ?
Matlab doesn't return any error and run correctly I am just not sure if it is the right way to do it.
Thanks in advance

6 Commenti

You should check whether the design vector x is identical in both "costfun" and "nonlcon". If this is the case, you can proceed as you described.
Best wishes
Torsten.
No that's exactly my problem, my x vector represents parameter that intervene indirectly in the computation of u, but then I still need to constraint these u...
When I put the noncol function as I described it Matlab finds different results than if I don't put the constraint function, I am just not sure if it does what I need it to do.
Thanks for the answer
To be safe, just calculate your u both in "costfun" and in "nonlcon" from the design vector x.
Best wishes
Torsten.
Ok thank for the advice, one last question, is it correct to use the "c" variable ? Because in the description of fmincon it shows c as c(x) which is not really the case for me, it's more c(u(v(x))) does it matter ?
Thanks a lot
No. As you can see from your notation c(u(v(x))): In the end, everything depends on x.
Best wishes
Torsten.
All right, just to conclude on this topic and for those who might want an answer:
it didn't change anything to compute the variable in the constraint function directly or to pass it as global, I got the same results
Cheers

Accedi per commentare.

Risposte (0)

Categorie

Richiesto:

il 8 Mar 2017

Commentato:

il 8 Mar 2017

Community Treasure Hunt

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

Start Hunting!

Translated by