Setting conditions for optimization variables

We are now setting the conditions for the following optimization variables.
x = optimvar('x', 100, 'LowerBound', 0)
showbounds(x)
Then,
0<=x(1)
0<=x(2)
・・・
0<=x(100).
How do we write the code to add the following condition?
We want to add an upperbond=0 in the interval 1 < x < 10.
0<=x(1)<=0
0<=x(2)<=0
・・・
0<=x(10)<=0
0<=x(11)
0<=x(12)
・・・
0<=x(100)

 采纳的回答

x = optimvar('x', 100, 'LowerBound', 0);
ub = Inf(100,1);
ub(1:10) = zeros(10,1);
x.UpperBound = ub;
showbounds(x)
0 <= x(1) <= 0 0 <= x(2) <= 0 0 <= x(3) <= 0 0 <= x(4) <= 0 0 <= x(5) <= 0 0 <= x(6) <= 0 0 <= x(7) <= 0 0 <= x(8) <= 0 0 <= x(9) <= 0 0 <= x(10) <= 0 0 <= x(11) 0 <= x(12) 0 <= x(13) 0 <= x(14) 0 <= x(15) 0 <= x(16) 0 <= x(17) 0 <= x(18) 0 <= x(19) 0 <= x(20) 0 <= x(21) 0 <= x(22) 0 <= x(23) 0 <= x(24) 0 <= x(25) 0 <= x(26) 0 <= x(27) 0 <= x(28) 0 <= x(29) 0 <= x(30) 0 <= x(31) 0 <= x(32) 0 <= x(33) 0 <= x(34) 0 <= x(35) 0 <= x(36) 0 <= x(37) 0 <= x(38) 0 <= x(39) 0 <= x(40) 0 <= x(41) 0 <= x(42) 0 <= x(43) 0 <= x(44) 0 <= x(45) 0 <= x(46) 0 <= x(47) 0 <= x(48) 0 <= x(49) 0 <= x(50) 0 <= x(51) 0 <= x(52) 0 <= x(53) 0 <= x(54) 0 <= x(55) 0 <= x(56) 0 <= x(57) 0 <= x(58) 0 <= x(59) 0 <= x(60) 0 <= x(61) 0 <= x(62) 0 <= x(63) 0 <= x(64) 0 <= x(65) 0 <= x(66) 0 <= x(67) 0 <= x(68) 0 <= x(69) 0 <= x(70) 0 <= x(71) 0 <= x(72) 0 <= x(73) 0 <= x(74) 0 <= x(75) 0 <= x(76) 0 <= x(77) 0 <= x(78) 0 <= x(79) 0 <= x(80) 0 <= x(81) 0 <= x(82) 0 <= x(83) 0 <= x(84) 0 <= x(85) 0 <= x(86) 0 <= x(87) 0 <= x(88) 0 <= x(89) 0 <= x(90) 0 <= x(91) 0 <= x(92) 0 <= x(93) 0 <= x(94) 0 <= x(95) 0 <= x(96) 0 <= x(97) 0 <= x(98) 0 <= x(99) 0 <= x(100)
It would probably be better to remove x(1) through x(10) from your problem, but suit yourself.
Alan Weiss
MATLAB mathematical toolbox documentation

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Get Started with Optimization Toolbox 的更多信息

产品

版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by