Info

この質問は閉じられています。 編集または回答するには再度開いてください。

how can i change this code

1 回表示 (過去 30 日間)
praveen thakur
praveen thakur 2020 年 2 月 19 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
clear all
close all
clc
clear workspace;
fun=[1,-1,-1];
coeff=[0,2.5,1; 0,1.5,2; 0,-1,5];
const=[70;100;0];
eqs=[1;1;1];
sign=[1,1,1];
slack=eye(3);
table=[zeros(1,1),fun,zeros(1,4);zeros(3,1),coeff,slack,const;zeros(1,8)];
disp('table=');
disp(table);
for i=2:4
tmp=-table(1,i);
for j=2:4
tmp = tmp + (table(j,i)*table(j,1));
end
table(5,i)=tmp;
end
minim=min(table(5,:));
while minim<0
index = find(table(5,2:7)==min(table(5,2:7)));
index = index+1;
mini = inf;
in = 0;
for i=2:4
tmp = table(i, 8)/table(i, index);
if tmp<mini && tmp>0
mini = tmp;
in = i;
end
end
pivot = table(in,index);
for j=2:8
table(in, j) = table(in, j)/pivot;
end
for i=2:5
if i~=in
tmp=table(i, index);
for j=2:8
table(i,j) = table(i,j)-((tmp*table(in,j))/pivot);
end
end
end
table(in, 1) = table(1,index);
minim = min(table(5,:));
end
disp(table);
disp('Maximum value of z=');
disp(table(5,8));
  3 件のコメント
praveen thakur
praveen thakur 2020 年 2 月 19 日
i am getting an error in line 36 that si array indices should be positive or logical value
madhan ravi
madhan ravi 2020 年 2 月 19 日
Don’t use table as a variable name, there’s an inbuilt function table()

回答 (1 件)

KSSV
KSSV 2020 年 2 月 19 日
in = 0 ;
pivot = table(in,index);
In the above line you have indexed in to zero. There is no zero and negaitve indices in MATLAB. You should change it to 1.
in = 1 ;
pivot = table(in,index);
Also there are some warnings in the code. There is divison with zero. Read about matlab indexing.

タグ

製品


リリース

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by