N
N
Nikita Sokolov2020-02-05 11:10:36
MATLAB
Nikita Sokolov, 2020-02-05 11:10:36

The submatrix is ​​incorrectly defined. Where is the mistake?

I'm making a program in scilab, but there doesn't seem to be such a tag.

The problem is in the part of the code where I am trying to make formulas like y = 2x + 1 for the plot function from the constraint matrix Aeq and the right side of the inequalities beq. I knew that the error was there because the first disp in the loop prints values, and then the program throws an error and stops working. Error text:

exec('/Users/nikita/Desktop/лабы/scilab/lab4/lab4.sce', -1)

   4.242D-16
  -4.
на строке    19 исполняемого файла /Users/nikita/Desktop/лабы/scilab/lab4/lab4.sce

Подматрица некорректно определена.

The program code itself:

//Использую вариант (c)

c = [1; 2];
Aeq = [
1, 1;
3, 1;
1, 5;
1, 0;
0, 1;
];
beq = [4; 4; 4; 3; 3];
n = length(beq) - 1;
xv = zeros(n);
yv = zeros(n);
x = zeros(n+1);
y = zeros(n+1);

for i = 1:n
   K = [
   Aeq(i, 1), Aeq(i, 2);
   Aeq(i+1, 1), Aeq(i+1, 2)
   ];
   k = [beq(i); beq(i+1)];
   x0 = linsolve(K, k);
   xv(i) = abs(x0(1));
   yv(i) = abs(x0(2));
   
   disp(x0);
   
   if ((Aeq(i, 1) <> 0) && (Aeq(i, 2) <> 0)) then //ОШИБКА ГДЕ-ТО ТУТ
      x(i) = 0:0.1:4;
      y(i) = (beq(i) - Aeq(i, 1) * x(i))/Aeq(i, 2);
   elseif (Aeq(i, 1) == 0) then
      y(i) = [beq(i); beq(i)];
      x(i) = [0; 4];
   else
      y(i) = [0; 4];
      x(i) = [beq(i); beq(i)];
   end
   
   disp(y, x);
   
   plot2d(x(i), y(i));
   
end

if ((Aeq(n+1, 1) <> 0) && (Aeq(n+1, 2) <> 0)) then
   x(n+1) = 0:0.1:4;
   y(n+1) = (beq(n+1) - Aeq(n+1, 1) * x(n+1))/Aeq(n+1, 2);
elseif (Aeq(n+1, 1) == 0) then
   y(n+1) = [beq(n+1); beq(n+1)];
   x(n+1) = [0; 4];
else
   y(n+1) = [0; 4];
   x(n+1) = [beq(n+1); beq(n+1)];
end

plot2d(x(n+1), y(n+1));

a=gca();
a.data_bounds=[0,0;4,4];

I don't know much about syllabus, so I can't figure out what the problem is. The program itself, in the end, should show the solution of linear programming problems using a graphical method (draw restrictions, highlight the area of ​​​​admissible values ​​and show the optimum point)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question