Hello, I am trying to create a problem based optimization problem for minimazing.
To summer it up, I want to do this optimization and I don't know how to do what I have in bold:
array1 = array2 - array3 .* (optimization_variable);
A=sum(array1(array1>0));
objective = A;
Is there any way to put conditionals in an optimization problem?
Thanks in advance

 채택된 답변

Bruno Luong
Bruno Luong 2022년 12월 7일
편집: Bruno Luong 2022년 12월 7일

1 개 추천

Could you try this equivalent expression
A=sum(array1.*(array1>0));

댓글 수: 3

Gerard Burjalès
Gerard Burjalès 2022년 12월 7일
Thanks for your comment but it is not working.
I think that the problem is due to the fact that it is an optimizationExpresion so the comparison doesn't work.
I am adding the error, the same I had before, that I get:
Error using ()
Subscripting into a table using one subscript (as in t(i)) is not supported. Specify a row subscript and a variable subscript, as in t(rows,vars). To select variables, use t(:,i) or for one variable t.(i). To select rows, use t(i,:).
Error in optim.internal.problemdef.display.writeExtraParams
Error in optim.problemdef.OptimizationExpression/expandNonlinearStr
Error in optim.internal.problemdef.display.showDisplay
Error in optim.problemdef.OptimizationProblem/expandObjectives2str
Error in optim.internal.problemdef.ProblemImpl/expand2str
Error in optim.internal.problemdef.ProblemImpl/showproblem
Error in optim.internal.problemdef.ProblemImpl/show
Bruno Luong
Bruno Luong 2022년 12월 7일
편집: Bruno Luong 2022년 12월 7일
May be you should relax the if test and replace it with one of the sigmodid function
S = @(x) atan(x)/(pi/2); % select the function you want
scale = ... ; small number appropriate for array1.
A = sum(array1.*((S(array1/scale)+1)/2));
Gerard Burjalès
Gerard Burjalès 2022년 12월 7일
Thanks for solving the issue and for the warm welcome in this community

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Linear Programming and Mixed-Integer Linear Programming에 대해 자세히 알아보기

질문:

2022년 12월 7일

편집:

2022년 12월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by