Why do I get the following error using fmincon?

조회 수: 5 (최근 30일)
CT
CT 2020년 2월 27일
편집: Matt J 2020년 2월 27일
I am trying to run the following fmincon problem, where evaluating fun requires to solve a linear programming problem.
Before showing you my code, let me write the optimisation problem in math symbols.
where x is a vector, is a vector of zeros, means that every element of x should be non-negative, are vectors of real numbers.
clear
rng default
XZW_temp=[0.5450 0.8175 -0.5451 0.2724]; %this is A1 above
X1_temp=[0 0.0852 0 -0.0852]; %this is A2 above
X2_temp=[2.0132 1.0066 -2.0132 -1.0066]; %this is A3 above
options = optimset('linprog');
options.Display = 'off';
fun=@(x)inner_max(x,XZW_temp, X1_temp, X2_temp, options);
ub=Inf*ones(4,1);
lb=zeros(4,1);
x0=ones(4,1);
[~, f]=fmincon(fun,x0,[],[],[],[],lb,ub);
The function inner_max is
function i_m=inner_max(x,XZW_temp, X1_temp, X2_temp, options)
f=-[x.'*XZW_temp.'; x.'*X1_temp.'; x.'*X2_temp.'];
Aeq=[1 0 0];
beq=1;
lb=-Inf*ones(3,1);
ub=Inf*ones(3,1);
[~,fval] = linprog(f,[],[],Aeq,beq,lb,ub,options);
i_m=-fval;
end
I get the following error
In an assignment A(:) = B, the number of elements in A and B must be the same.
Error in finitedifferences
Error in computeFinDiffGradAndJac
Error in barrier
Error in fmincon (line 798)
[X,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN] = barrier(funfcn,X,A,B,Aeq,Beq,l,u,confcn,options.HessFcn, ...
Could you help me to understand what is wrong?
  댓글 수: 5
Matt J
Matt J 2020년 2월 27일
Never mind. You should be using fminimax, though.
CT
CT 2020년 2월 27일
Thanks, but could not understand how to use fminimax in my case. In the examples the inner maximisation problem is always "discrete".

댓글을 달려면 로그인하십시오.

채택된 답변

Matt J
Matt J 2020년 2월 27일
편집: Matt J 2020년 2월 27일
Because the are unconstrained, the only way the inner max operation can have a finite result is if [A1;A2]*x=[0;0] and therefore the problem is equivalent to the linear program,
You can plug this into linprog
f=[0.5450 0.8175 -0.5451 0.2724]; %this is A1 above
A2=[0 0.0852 0 -0.0852]; %this is A2 above
A3=[2.0132 1.0066 -2.0132 -1.0066]; %this is A3 above
Aeq=[A2;A3]; beq=[0;0];
lb=zeros(4,1);
x=linprog(f,[],[],Aeq,beq,lb)
However, it finds that the problem is unbounded,
Problem is unbounded.
x =
[]

추가 답변 (1개)

Matt J
Matt J 2020년 2월 27일
편집: Matt J 2020년 2월 27일
Could you help me to understand what is wrong?
linprog() and therefore innermax() can return an empty matrix [] when it does not find a solution. Your code does not test for and provide a contingency for that situation.

카테고리

Help CenterFile Exchange에서 Nonlinear Optimization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by