matlab等式操作,等式和等式约束

创建一个名为 x 的 4×6 优化变量矩阵。

x = optimvar('x',4,6);

创建 x 的每行总和为 1 的等式。

constrsum = sum(x,2) == 1

constrsum =

4x1 Linear OptimizationEquality array with properties:

IndexNames: {{} {}}

Variables: [1x1 struct] containing 1 OptimizationVariable

See equality formulation with show.

查看等式。

show(constrsum)

(1, 1)

x(1, 1) + x(1, 2) + x(1, 3) + x(1, 4) + x(1, 5) + x(1, 6) == 1

(2, 1)

x(2, 1) + x(2, 2) + x(2, 3) + x(2, 4) + x(2, 5) + x(2, 6) == 1

(3, 1)

x(3, 1) + x(3, 2) + x(3, 3) + x(3, 4) + x(3, 5) + x(3, 6) == 1

(4, 1)

x(4, 1) + x(4, 2) + x(4, 3) + x(4, 4) + x(4, 5) + x(4, 6) == 1

要在优化问题中包含等式,请使用圆点表示法将 Constraints 属性设置为 constrsum。

prob = optimproblem;

prob.Constraints.constrsum = constrsum

prob =

OptimizationProblem with properties:

Description: ''

ObjectiveSense: 'minimize'

Variables: [1x1 struct] containing 1 OptimizationVariable

Objective: [0x0 OptimizationExpression]

Constraints: [1x1 struct] containing 1 OptimizationConstraint

See problem formulation with show.

同样,要在方程问题中包含等式,请使用圆点表示法将 Constraints 属性设置为 constrsum。

eqnprob = eqnproblem;

eqnprob.Equations.constrsum = constrsum

eqnprob =

EquationProblem with properties:

Description: ''

Variables: [1x1 struct] containing 1 OptimizationVariable

Equations: [1x1 struct] containing 1 OptimizationEquality

See problem formulation with show.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值