Use simplex method to maximize π = 4π₯ + 5π¦ subject to the conditions π₯ + 2π¦ β€ 5 π₯ β 2π¦ β€ 2 βπ₯ + π¦ β€ 2 2π₯ + π¦ β€ 6 and π₯, π¦ β₯ 0.
close all,
clear all,
clc,
disp('Use simplex method to maximize f = 4x + 5y subject to the conditions ');
disp('x+2y <= 5');
disp('x-2y <= 2');
disp('-x+y <= 2');
disp('2x+y <= 6');
disp('x,y >= 0');
disp(' ');
f = [-4; -5];
A =Β [1, 2;
Β Β Β 1, -2;
Β Β Β -1, 1;
Β Β Β 2, 1];
b = [5; 2; 2; 6];
lb=zeros(2,1);
ub=[1e4;1e4];
Aeq=[];
beq=[];
x0=[];
[x,fval,exitflag,output] = linprog(f,A,b,Aeq,beq,lb,ub,x0);
disp(['x = ',num2str(x(1)),'32,',', y = ',num2str(x(2))]);
disp(['Max f = ',num2str(fval)]);
Comments
Leave a comment