How to pass to the objective function just the elements of a matrix that satisfy my constraints

2 views (last 30 days)
Hi everybody,
I'm working with fmincon function. My objective function operates on matrices and at the end it makes the std dev of such matrices. Therefore, it comes out with a number that need to be minimized through the fmincon function. Constraints work on elements of the matrices (< or > of a certain threshold). At this point I would like to know how to pass to the objective function just the values of matrices that satisfy my constrains or another method to pass to the objective function just the indexes of the values that satisfy constraints.
Thank you in advance.
N.

Accepted Answer

Matt J
Matt J on 22 Jul 2015
Edited: Matt J on 22 Jul 2015
Well, extracting the elements of a matrix M that satisfy a threshold is easy
indicesLogical = M>threshold;
values = M(indicesLogical)
but the objective function needs to receive the entire matrix you are optimizing over as input. If it needs to process some elements differently than others you would index/extract them as above, but inside the objective function, not prior to it.
  2 Comments
Nelson
Nelson on 18 Aug 2015
Edited: Nelson on 18 Aug 2015
Thanks Matt for your answer.
Is it correct then to use the fminunc function inserting some controls into the objective function in order to avoid the use of constraints? I mean, if I include controls inside the objective function I don't need the definition of constraints anymore.
Thanks.
Regards
Matt J
Matt J on 19 Aug 2015
Edited: Matt J on 19 Aug 2015
No, that is not correct.
Nothing that you've mentioned in your posted question appears to have anything to do with actual constraints. A constraint is something that the unknown variables must satisfy in order to be considered a possible solution. All you've told us is that your objective function has a different dependence on different elements x(i) of the vector x depending on whether x(i) is greater than some threshold.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!