# Why does the rowsize of A matter in fmincon

1 ビュー (過去 30 日間)
Martin Baumgärtner 2019 年 1 月 22 日
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?

#### 0 件のコメント

サインイン to comment.

### 採用された回答

Alan Weiss 2019 年 1 月 22 日
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

#### 1 件のコメント

Martin Baumgärtner 2019 年 1 月 22 日
Thank you very much!

サインイン to comment.

### その他の回答 (1 件)

Walter Roberson 2019 年 1 月 22 日
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 件のコメント

Martin Baumgärtner 2019 年 1 月 22 日
Thank you for your very quick answer. Can you also explain to me why the result is affected?

サインイン to comment.

サインイン してこの質問に回答します。

R2018a

Translated by