0% found this document useful (0 votes)
3 views2 pages

Linear Programming Optimal Solution

Uploaded by

Asmi
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)
3 views2 pages

Linear Programming Optimal Solution

Uploaded by

Asmi
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

Name - Asmi luthra

clc Roll no - 1024230111


clear all;
2w13
M = 1000;
c = [3 2 0 -M -M]; % Coefficients of x1, x2, s1, a1, a2
A = [1 1 -1 1 0;1 2 0 0 1];
b = [4; 6];

[m, n] = size(A);

bv_index = n-m+1:1:n;
Y = [A b];

for s = 1:50

cb = c(bv_index);
Xb = Y(:, end)
z = cb * Xb;
zjcj = cb * Y(:, 1:n) - c

if (zjcj >= 0)
disp('Optimal solution achieved');
X = zeros(1, n);
X(bv_index) = Xb;
fprintf('Basic variables: '); disp(bv_index);
fprintf('Optimal solution X = '); disp(X);
fprintf('Optimal objective function value = %f\n', z);
break;
else
[a, EV] = min(zjcj)
if (Y(:, EV) < 0)
disp('Unbounded solution');
break;
else
for j = 1:m
if Y(j, EV) > 0
ratio(j) = Xb(j) / Y(j, EV);
else
ratio(j)=inf
end
end
end
[k, LV] = min(ratio)
bv_index(LV) = EV;
end
pivot = Y(LV, EV);
Y(LV, :) = Y(LV, :) ./ pivot;
for i = 1:m
if i ~= LV
Y(i, :) = Y(i, :) - Y(i, EV) * Y(LV, :);
end
end
end
OUTPUT

You might also like