1

I am solving the following linear programming problem, I am guiding myself on the documentation

Documentation Matlab

Every time I execute I get the following error

Dimensions of matrices being concatenated are not consistent.

I have the objective function and restrictions as follows

%F.O
f=[0.669 0.654 0.503 0.683 0.670 0.673 0.749 0.655 0.660 0.583 1.243 0.639 2.024 2.156 1.672 0.473 0.139 0.687];

%Restrictions
Aeq=[0.1 0.12 0.335 0.15 0.18 0.19 0.12 0.15 0.15 0.15 0.15 0.11 0.13 0.46;
    0.3 0.24 0.03 0.05 0.04 0.27 0.03 0.24 0.15 0.52 0.52;
    0.1 0.12 0.31 0.15 0.19 0.08 0.2 0.12 0.15 0.50 0.34 0.44;
    0.26 0.50;
    0.06 0.17];

b=[285.71; 305.33; 450; 262.50; 41.50];

and I execute it with the following command

x=linprog(f,Aeq,b)

The restrictions take them out of the following exercise

Exercise

This should be the result of z

Result

1 Answer 1

1

A matrix must have the same number of columns in each row. Aeq in your case has different number of columns.

How to fix it?

The variables missing in the equations of constraints have zero coefficients. So:

%Objective Function
     %X1    X2    X3    X4    X5    X6    X7    X8    X9    X10   X11   X12   X13   X14   X15   X16   X17   X18
f = [0.669 0.654 0.503 0.683 0.670 0.673 0.749 0.655 0.660 0.583 1.243 0.639 2.024 2.156 1.672 0.473 0.139 0.687];

A = [];   b = [];   %No inequality constraints

%Equality Constraints are:
     %X1  X2    X3   X4   X5   X6   X7   X8   X9   X10  X11   X12  X13  X14  X15  X16  X17  X18
Aeq=[0.1 0.12 0.335 0.15 0.18 0.19 0.12 0.15 0.15 0.15   0   0.15 0.11  0   0.13  0     0  0.46; %Nitrogeno
     0.3 0.24   0   0.03 0.05 0.04 0.27 0.03 0.24 0.15   0    0   0.52 0.52  0    0     0    0 ; %Fosforo
     0.1 0.12   0   0.31 0.15 0.19 0.08 0.2  0.12 0.15  0.50  0    0   0.34 0.44  0     0    0 ; %Potasio
      0    0    0    0    0    0    0    0    0    0     0   0.26  0    0    0    0    0.50  0 ; %Calcio
      0    0    0    0   0.06  0    0    0    0    0     0    0    0    0    0   0.17   0    0]; %Magnesio

beq = [285.71; 305.33; 450; 262.50; 41.50]; %What you defined as 'b' is actually `beq`

lb = zeros(18,1);   ub = inf(18,1);         %Bounds

[x, Optimal_sol] = linprog(f, A, b, Aeq, beq, lb, ub);

>> x
x =
   1.0e+03 *
    0.7142
         0
         0
    1.0268
         0
         0
         0
         0
         0
    0.4018
         0
         0
         0
         0
         0
    0.2441
    0.5250
         0

>> Optimal_sol
Optimal_sol =
   1.6018e+03
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.