MATLAB: Linprog error – The number of rows in A must be the same as the number of elements of f & Error in [x fval] = linprog(f,​A,b,Aeq,be​q,lb,ub);

linear optimizationlinprogMATLABoptimizationOptimization Toolbox

Hi , I am trying to do a linprog optimisation by referring to the example in Matlab. I need help to solve the errors. Ty.
my code is:
variables = {'e1','e2','p1','p2','a','c','k','m','y','z'};
N = length(variables);
% create variables for indexing
for v = 1:N
eval([variables{v},' = ', num2str(v),';']);
end
% Lower Bound Constraints
lb = zeros(size(variables));
lb([e1,e2,p1,p2]) = [14.4,14.4,26.4,28.8];
% Upper Bound Constraints
ub = Inf(size(variables));
ub([e1,e2,p1,p2,k,m]) = [48,48,84,84,2.5,2.5];
% Other Constraints
A = zeros(2,4);
A(1,k) = 1; A(1,e2) = -1/36; b(1) = 1.7;
A(2,m) = -1; A(2,p2) = -1/36; b(2) = 1.7;
Aeq = zeros(2,4); beq = zeros(2,1);
Aeq(1,[a,e1]) = [1,-7/30];
Aeq(2,[c,p1]) = [1,-7/60];
% Objective function
if a <= c
y = a;
else
y = c;
end
if k <= m
z = k;
else
z = m;
end
f = z*y*24768;
% Solve the Problem with linprog
[x, fval] = linprog(f,A,b,Aeq,beq,lb,ub);
for d = 1:N
fprintf('%12.2f \t%s\n',x(d),variables{d})
end
fval;

Best Answer

Um, your objective is a product of z and y, which are in turn derived from the parameters.
This is NOT LINEAR programming. linprog will not be able to solve your problem as you have posed it.
Related Question