matlab约束转非约束,请问:fmincon非等和等于的约束条件

参考了以前约束条件的帖子, 照猫画虎也不成,约束条件报错啦,请大牛牛们指点我一下。谢谢啦。。。

要约束的是, 系数x(1)+x(2)=1,  对于每一行A(i,:)和T拟合的结果, x(3)要小于x(4)。

function main

clear all

close all

clc

A=[201,107,198,176,59,140,134,55,83,108,65,56,72,59,37,67,48,17,34,24;

179,85,199,154,51,176,100,47,116,95,44,96,79,31,70,61,35,39,41,24;

221,114,177,173,83,105,139,78,52,89,78,45,50,60,27,32,41,24,6,24];

T=[3.41 6.63 9.85 13.07 16.29 19.52 22.74 25.96 29.18 32.40 35.62 38.84 42.06 45.29 48.51 51.73 54.95 58.17 61.39 64.61];

Aeq=[];beq=[];lb=[0;0;0];ub=[1;1;1];x0=[0.6;0.4;0.030;0.038];

fun = @(x) x(1)*(-exp(-x(3)*T))+x(2)*(-exp(x(4)*T));

opts1 = optimset('Algorithm','interior-point');

opts2 = optimset('Algorithm','sqp');

opts3 = optimset('Algorithm','trust-region-reflective');

opts4 = optimset('Algorithm','active-set');

for i =1:3;

problem1 = createOptimProblem('fmincon','objective',...

fun,'x0',x0, 'Aineq', A(i,:), 'bineq', T, 'nonlcon', @mycon, 'options',opts1);

problem2 = createOptimProblem('fmincon','objective',...

fun,'x0',x0, 'Aineq', A(i,:), 'bineq', T, 'nonlcon', @mycon, 'options',opts2);

problem3 = createOptimProblem('fmincon','objective',...

fun,'x0',x0, 'Aineq', A(i,:), 'bineq', T, 'nonlcon', @mycon, 'options',opts3);

problem4 = createOptimProblem('fmincon','objective',...

fun,'x0',x0, 'Aineq', A(i,:), 'bineq', T, 'nonlcon', @mycon, 'options',opts4);

gs = GlobalSearch;

[x1,fval1] = run(gs,problem1)

[x2,fval2] = run(gs,problem2)

[x3,fval3] = run(gs,problem3)

[x4,fval4] = run(gs,problem4)

end

end

function[c,ceq]=mycon(x)

x(4)>=x(3);

x(1)+x(2)-1=0;

end

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值