Senin, 02 Juni 2014

Program Pascal Metode Simplex

uses crt;
var
matrix1: array[1..5,1..5] of real ;
matrix2: array[1..5,1..5] of real;
kondisi: Boolean ;
temp,kolom_kunci,baris_kunci:real ;
x1,x2,z,nilaikunci,temp1,temp2,temp3: real ;
i,indexkolomkunci,indexbariskunci,j,indexbariskuncibaru:integer;

begin
clrscr;
matrix1[1,1]:=-5;
matrix1[1,2]:=-1;
matrix1[1,3]:=0;
matrix1[1,4]:=0;
matrix1[1,5]:=0;
matrix1[2,1]:=2;
matrix1[2,2]:=1;
matrix1[2,3]:=1;
matrix1[2,4]:=0;
matrix1[2,5]:=6;
matrix1[3,1]:=1;
matrix1[3,2]:=-1;
matrix1[3,3]:=0;
matrix1[3,4]:=1;
matrix1[3,5]:=0;

kondisi:=False ;
kolom_kunci:=0;
i:=1;
for j := 1 to 4 do
if matrix1[i,j] < kolom_kunci then
begin
kolom_kunci:=matrix1[i,j];
indexkolomkunci:=j;
end;
writeln('indexkolomkunci=',indexkolomkunci);
baris_kunci:=999;
j:=5;
for i := 2 to 3 do
if ((matrix1[i,j] <>0)) then
begin
baris_kunci:=matrix1[i,j];
indexbariskunci:=i;
end;
writeln('indexbariskunci=',indexbariskunci);
if kolom_kunci = 0 then
begin
kondisi:=True;
z:=matrix1[1,5];
x1:=matrix1[2,5];
x2:=matrix1[3,5];
end
else
begin
nilaikunci:=matrix1[indexbariskunci,indexkolomkunci];
writeln('nilaikunci=',nilaikunci);
i:=indexbariskunci;
for j := 1 to 5 do
begin
matrix2[i,j]:=matrix1[i,j]/nilaikunci;
end;
i:=1;
writeln('indexkolomkunci=,indexkolomkunci');
for j := 1 to 5 do
matrix2[i,j]:=matrix1[i,j]-(matrix1[i,indexkolomkunci] * matrix2[indexbariskunci,j]);

baris_kunci:=0;
j:=5;
for i := 2 to 3 do
if matrix1[i,j] <= baris_kunci then
begin
baris_kunci:=matrix1[i,j];
indexbariskuncibaru:=i;
end;

i:=indexbariskuncibaru;
writeln('indexbariskuncibaru',i);
for j:= 1 to 5 do
matrix2[i,j]:=matrix1[i,j]-(matrix1[i,indexkolomkunci]* matrix2[indexbariskunci,j]);


for i:= 1 to 3 do
for j:=1 to 5 do
matrix1[i,j]:=matrix2[i,j];
end;


z:=matrix1[1,5];
x1:=matrix1[2,5];
x2:=matrix1[3,5];
writeln('nilai z=',z);
writeln('nilai x1=',x1);
writeln('nilai x2=',x2);

readln;

end.

Tidak ada komentar:

Posting Komentar