Error using SumOperator with Optimization Variables

조회 수: 2 (최근 30일)
Andra Vartolomei
Andra Vartolomei 2022년 8월 14일
댓글: Torsten 2022년 8월 14일
I have an Optimization Problem where I created the optim. variable x and the optim. problem linoptim.
Now I am trying to define my constraints and I keep getting an Error
nTasks = 3;
nRess = 2;
maxPT = 50;
x = optimvar('x',nTasks,nRess,maxPT,'Type', 'integer','LowerBound',0,'UpperBound',1);
Constraint1 = sum(x,[2 3]) == ones(nTasks, 1);
"Error in using optim.internal.problemdef.SumOperator
Dimension argument must be a positive integer scalar within indexing range.
If I write the same command and instead of x am using a matrix it works just fine:
sum(rand ([3 2 50]), [2 3])

채택된 답변

Torsten
Torsten 2022년 8월 14일
nTasks = 3;
nRess = 2;
maxPT = 50;
x = optimvar('x',nTasks,nRess,maxPT,'Type', 'integer','LowerBound',0,'UpperBound',1);
Constraint1 = sum(sum(x,2),3) == ones(nTasks,1);
  댓글 수: 2
Andra Vartolomei
Andra Vartolomei 2022년 8월 14일
Thank you! :)
Torsten
Torsten 2022년 8월 14일
Little deficits of problem-based programming ...

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Linear Least Squares에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by