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.
clearrng defaultXZW_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 finitedifferencesError in computeFinDiffGradAndJacError in barrierError 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?
Best Answer