Find KKT solution to a given problem
显示 更早的评论
I'm trying to solve kkt problem with matlab but I'm having problem with my code, please, I want some one to assist me in correcting errors in my codes
problem:
Maximize R= 208*x1**0.323168*x2**0.172084*x3**0.085998*x4**0.188794*x5**0.229956
subject to:
2.8 * x1 + 22 * x2 + 4 * x3 + 0.272 * x4 + x5 <= 492
22 * x2 + 4 * x3 <= 212
x5 <= 20
Bounds
x1= (lb = 40, ub = 80)
x2= (lb = 5, ub = 12)
x3= (lb = 4, ub = 11)
x4= (lb = 20, ub = 70)
x5= (lb = 7, ub = 20)
X0 = [41,6,5,22,8]
Proposed solution:
fun = @(x)-208*x(1)^0.323168*x(2)^0.172084*x(3)^0.085998*x(4)^0.188794*x(5)^0.229956;
x0=[41,6,5,22,8]; %initial guess for the solution
%express first constraint in the form A*x<=b:
Aeq=[41,6,5,22,8];
beq = 1;
A=[2.8,22,4,0.272]; b=492;
C=[0,22,4,0,0]; d=212;
E=[0,0,0,0,1]; f=20;
%express constraints 2 and 3 by defining vectors lb and ub:
lb=[40,5,4,20,7]; %no lower blound constraints
ub=[80, 12,11,70,20]; %upper bounds on x(4),x(5)
[x,fval,exitflag,output,lambda]=fmincon(fun,x0,A,b,[],[],lb,ub);
disp(x) %value of x at the solution
disp(-fun(x)); %value of the function you wanted to maximize
disp(A*x') %check constraint 1
disp(lambda)
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Genetic Algorithm 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!