参考了以前约束条件的帖子, 照猫画虎也不成,约束条件报错啦,请大牛牛们指点我一下。谢谢啦。。。
要约束的是, 系数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