Why does the rowsize of A matter in fmincon

1 view (last 30 days)
I have a Matlab code, which use fmincon with some constraints. So that I am able to modify the code I have thought about whether the line position within the condition matrix A makes a difference
I set up a test file so I can change some variables. It turns out that the position of the condition is irrelevant for the result, but the number of rows in A and b plays a role. I´m suprised by that because I would expect that a row with only zeros in A and b just cancel out.
fun = @(x)100*(x(2)-x(1)^2)^2 + (1-x(1))^2;
options1 = optimoptions('fmincon','Display','off');
A=zeros(2,2); %setup A
A(2,2)=1; %x2<0
b=[0 0]'; %setup b
x = fmincon(fun,[-1,2],A,b,[],[],[],[],[],options1);x
%change condition position inside A
A=zeros(2,2);
A(1,2)=1; %x2<0
b=[0 0]';
x = fmincon(fun,[-1,2],A,b,[],[],[],[],[],options1);x
% no chance; the position doesn´t influence fmincon
%change row size of A
A=zeros(1,2);
A(1,2)=1; %x2<0
b=[0]';
x = fmincon(fun,[-1,2],A,b,[],[],[],[],[],options1);x
%change in x2
%increase size of A
A=zeros(10,2);
A(1,2)=1; %x2<0
b=[0 0 0 0 0 0 0 0 0 0]';
x = fmincon(fun,[-1,2],A,b,[],[],[],[],[],options1);x
%change in x2
Can someone explain to me why fmincon is influenced by the row number? What is the "right" rownumber in A and b? The number of variables or the number of conditions?

Accepted Answer

Alan Weiss
Alan Weiss on 22 Jan 2019
You should not use all-zero rows in A or Aeq. Each such row specifies a linear constraint that does not, in fact, exist. fmincon has to add the constraint to a list of constraints it is trying to satisfy, but there is nothing to satisfy. If you have no constraint at all, pass [] for the entry instead of a matrix with just zero entries.
Also, you should not have any row of A that has only one nonzero entry. Such a row represents a bound. Instead of representing a bound this way, represent it using the lb or ub arguments.
By giving constraints in these ways you allow fmincon to perform as efficiently as possible.
Alan Weiss
MATLAB mathematical toolbox documentation

More Answers (1)

Walter Roberson
Walter Roberson on 22 Jan 2019
A and b should have the same number of rows as there are separate linear inequality conditions. The number of columns should equal the number of variables for A and b should have one column. fmincon() might be generous and permit row vectors of b that are the right length.
Aeq and beq should have the same number of rows as there are separate linear equality conditions. The number of columns should equal the number of variables for Aeq and beq should have one column. fmincon() might be generous and permit row vectors of beq that are the right length.
  1 Comment
Martin Baumgärtner
Martin Baumgärtner on 22 Jan 2019
Thank you for your very quick answer. Can you also explain to me why the result is affected?

Sign in to comment.

Categories

Find more on Get Started with Optimization Toolbox in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!