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

조회 수: 2 (최근 30일)
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.

채택된 답변

Matt J
Matt J 2015년 7월 22일
편집: Matt J 2015년 7월 22일
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
Nelson
Nelson 2015년 8월 18일
편집: Nelson 2015년 8월 18일
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 2015년 8월 19일
편집: Matt J 2015년 8월 19일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by