Getting the "Error running optimization. Too many output arguments." when running fmincon with gradient option in derivatives.

2 views (last 30 days)
Hi,
I'm trying to optimize a problem of engine performance using a external function 'finter' (external deck - executable). That function works properly as I have checked it many times.
My objective function is as follows:
function [m]=fobjetivo(X)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%% Function to calculate the Obj Func %%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Tt41 = 1350;
Tt42 = 1500;
[y1] = finter(X,Tt41);
[y2] = finter(X,Tt42);
ys1 = [-1.60742937984057;-1.75941194993574;-1.52016066840023;-1.38821355190586;-1.26737524545974;-1.11748814435432;-0.968998107063983;-1.31351767471495;-1.48990020304618;-1.29056672044894];
ys2 = [-0.218867980285718;-0.146046874197578;-0.0918019106772645;-0.0117144187008822;0.101770383589507;0.238687435338204;0.389060531152024;0.0547756208261101;-0.0687671839852227;0.0390575624990874];
m = sqrt(((norm(y1-ys1))^2)+((norm(y2-ys2))^2));
end
I have only as constraints the following conditions:
a) The solution must count with all the components (the solution X counts with 10 components) in between 0 and 2. That's whay my UB and LB are as follows:
LB = [0;0;0;0;0;0;0;0;0;0]
UB = [2;2;2;2;2;2;2;2;2;2]
b) The components must be positive always. That's why my non-linear constraint function is as follows:
function [c,ceq] = nonlcon(x)
c=-prod(x) ;
ceq= [];
end
The initial point I use for the iterations is the following:
X0 = [0.0650000000000000; 1.12240000000000; 1.76370000000000; 1.33840000000000; 0.380900000000000; 0.737800000000000; 1.96330000000000; 1.96330000000000; 0.312800000000000; 1.71100000000000]
It is interesting that, when I select the option "approximate by solver" in the derivatives, the tool starts the optimization. Finally it says that the initial point given is a good solution:
Objective function value: 1.6591997092884727
Initial point is a local minimum that satisfies the constraints.
Optimization completed because at the initial point, the objective function is non-decreasing
in feasible directions to within the value of the optimality tolerance, and
constraints are satisfied to within the value of the constraint tolerance.
Obviously, that is not a valid answer because I know the solution of the problem is as follows:
Xsolv = [0.602900000000000; 1.40220000000000; 1.33270000000000; 1.07830000000000; 1.39620000000000; 1.33310000000000; 0.356300000000000; 0.256000000000000; 1.99820000000000; 0.342200000000000]
But, at least, the progam starts doing something.
With the "gradient" option in the derivatives the tool finds this problem:
Error running optimization.
Too many output arguments.
Any idea on where the issue may be?
My problem is quite dependant on the function. I know that some colleague has used the gradient succesfully in this very same problem and, frankly speaking, it seems the SQP-gradient seems to be the right approach here, but 'm not capable to make it work so far.
Thanks,
JRR
  2 Comments
Matt J
Matt J on 15 Jan 2021
b) The components must be positive always. That's why my non-linear constraint function is as follows:
That is already ensured by
LB = [0;0;0;0;0;0;0;0;0;0]
Also, prod(x)>=0 does not ensure that all componets are greater than zero, for example, x=-ones(1,10) satisfies the constraints but none of its elements are positive.

Sign in to comment.

Accepted Answer

Matt J
Matt J on 15 Jan 2021
Edited: Matt J on 15 Jan 2021
Any idea on where the issue may be?
It sounds like you have set SpecifyObjectiveGradient=true. However, it does not appear from your code that you have fobjetivo(X) performs any gradient calculation.
  4 Comments

Sign in to comment.

More Answers (0)

Categories

Find more on Introduction to Installation and Licensing in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!