-
Notifications
You must be signed in to change notification settings - Fork 1
/
simplexmax1505057.m
104 lines (89 loc) · 1.87 KB
/
simplexmax1505057.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
function [max] = simplexmax()
format short g;
A = [1 -1.75 -1.25 0 0 0 0;0 1.2 2.25 1 0 0 14;0 1 1.1 0 1 0 8;0 2.5 1 0 0 1 9;];
[ra ca]=size(A);
B=zeros(ra,1);
% making tableue with upper bound
X = [A B];
[rx cx]=size(X);
disp('Initial tableue');
% finding minimum in row 1
min = 0;
indexC = -1;
for i=2:cx-2
if(X(1,i)<min)
min=X(1,i);
indexC=i;
end
end
% updating uper bound
for i=2:rx
if(X(i,indexC)~=0)
X(i,cx)=X(i,cx-1)./X(i,indexC);
end
end
X
iter=0;
while(true)
% finding minimum in bound column
min = X(2,cx);
indexR = 2;
for i = 2:rx
if(X(i,cx)<min)
min = X(i,cx);
indexR=i;
end
end
% making all the other rows 0
for i= 1 : rx
if(i==indexR)
continue;
end
temp=X(i,indexC)./X(indexR,indexC);
for j = 2 : cx-1
X(i,j) = X(i,j)-temp.*X(indexR,j);
if(abs(X(i,j))<(10^-6))
X(i,j)=0;
end
end
end
X(1,cx)=0;
% making 1 in the pivot
temp=X(indexR,indexC);
for i = 2 : cx-1
X(indexR,i)=X(indexR,i)./temp;
end
% finding minimum in row 1
min = 0;
indexC = -1;
f=0;
for i=2:cx-2
if(X(1,i)<min)
min=X(1,i);
indexC=i;
f=1;
end
end
if(f==1)
% updating uper bound
for i=2:rx
if(X(i,indexC)~=0)
X(i,cx)=X(i,cx-1)./X(i,indexC);
end
end
end
iter=iter+1;
if(f==1)
fprintf('After iteration : %d ',iter);
X
else
fprintf('After iteration : %d (Final talbeue)',iter);
X(:,cx) = [];
X
max=X(1,cx-1);
end
if(f==0)
break;
end
end
end