0% found this document useful (0 votes)
43 views1 page

'Object Vector:' 'Constraints Matrix: ' 'Max or Min:' 'S': For For

This MATLAB code takes in an object vector, constraints matrix, and whether the optimization should be maximized or minimized. It then performs the following steps: 1) Sets up a matrix A combining the constraints matrix and object vector. 2) Loops through all possible variable combinations to test against constraints. 3) Stores valid combinations and their objective values in arrays. 4) Finds the minimum or maximum value as requested and displays the corresponding variables.

Uploaded by

Reda AlHamwi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views1 page

'Object Vector:' 'Constraints Matrix: ' 'Max or Min:' 'S': For For

This MATLAB code takes in an object vector, constraints matrix, and whether the optimization should be maximized or minimized. It then performs the following steps: 1) Sets up a matrix A combining the constraints matrix and object vector. 2) Loops through all possible variable combinations to test against constraints. 3) Stores valid combinations and their objective values in arrays. 4) Finds the minimum or maximum value as requested and displays the corresponding variables.

Uploaded by

Reda AlHamwi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

clc

clear
Ov=input('Object Vector:');
Cm=input ('Constraints Matrix: ');
A=[Cm;[0 1 0];[1 0 0];Ov 0];
O=input('Max or Min :' , 's');
k=1;
for i=1:size(A,1)-2
for j=i+1:size(A,1)-1
vbn=inv([A(i,1) A(i,2); A(j,1) A(j,2)])*[A(i,3);A(j,3)];
X(k)=vbn(1);
Y(k)=vbn(2);
Z(k)=A(size(A,1),1)*X(k)+A(size(A,1),2)*Y(k);
for gfe=1:size(Cm,1)
if A(gfe,1)*X(k)+A(gfe,2)*Y(k) <= A(gfe,3)
F1(gfe)=1;
else
F1(gfe)=0;
end
end
if X(k) >= 0
F1(gfe+1)=1;
else
F1(gfe+1)=0;
end
if Y(k) >= 0
F1(gfe+2)=1;
else
F1(gfe+2)=0;
end
G=prod(F1);
if G==0;
X1(k)=X(k);
X2(k)=Y(k);
Target(k)=-1;
else
X1(k)=X(k);
X2(k)=Y(k);
Target(k)=Z(k);
end
k=k+1;
end
end
hh=Target;
v=1;
while v <= length(hh)
if hh(v) == -1
hh(v)=[];
v=v-1;
end
v=v+1;
end
minimum=min(hh);
maximum=max(hh);
switch O
case 'Min'
rt=Target-minimum;
for e=1:length(rt)
if rt(e)==0;
qq=e;
disp('X1=')
disp(X1(qq))
disp('X2=')
disp(X2(qq))
disp('Minimum=')
disp(minimum)
end
end
case 'Max'
ru=Target-maximum;
for cc=1:length(ru)
if ru(cc)==0;
qj=cc;
disp('X1=')
disp(X1(qj))
disp('X2=')
disp(X2(qj))
disp('Maximum=')
disp(maximum)
end
end
end

You might also like