Error with FMINCON - Failure in initial user-supplied objective function evaluation

2 views (last 30 days)
Hi everybody,
I'm trying to run an optimization problem with FMINCON, but I keep getting the following error:
Error using ObjFun (line 3)
Not enough input arguments.
Error in fmincon (line 564)
initVals.f = feval(funfcn{3},X,varargin{:});
Caused by:
Failure in initial user-supplied objective function evaluation. FMINCON cannot continue.
This is the objective function:
function f= ObjFun (x,NumConnections,NodesToSearchFrom)
for t=1:NumConnections
DistCN(:,t)=abs(x(t)-NodesToSearchFrom);
end
for t=1:NumConnections
[Di(t), indx(t)]=min(DistCN(:,t));
end
f=sum(Di);
... and these are the constraints that are in another function:
function [c, ceq] = SideConstraints(x,NumConnections,NumInterNodes,UnfeasibleNodeArea,LowerBound,UpperBound,ConnectionCentre)
for k=1:NumConnections
for q=1:NumInterNodes
NodeConstraintsB(q,k)=x(k)-UnfeasibleNodeArea(q,1);
NodeConstraintsA(q,k)=-x(k)+UnfeasibleNodeArea(q,2);
end
end
c_B=reshape(NodeConstraintsB,[],1);
c_A=reshape(NodeConstraintsA,[],1);
c=[c_B;c_A;-x+LowerBound;x-UpperBound];
DistBetConnections=abs(ConnectionCentre(1)-ConnectionCentre(2));
ceq=[abs(x(1)-x(2))-DistBetConnections];
And the script to call the optimization procedure is this:
x0=[LowerBound; LowerBound+ConnectionCentre(2)];x=x0;
f= ObjFun (x,NumConnections,NodesToSearchFrom)
[c,ceq]=SideConstraints(x,NumConnections,NumInterNodes,UnfeasibleNodeArea,LowerBound,UpperBound,ConnectionCentre);
options=optimset('Display','iter');
OptimalResult=fmincon(@ObjFun,x0,[],[],[],[],[],[],@SideConstraints,options)
The general data is is another script but it's long so I didn't copy it here.
I've changed many things within the functions,including the input arguments but still can't work it out. I appreciate very much any help!
Best, Martha

Accepted Answer

Walter Roberson
Walter Roberson on 29 Nov 2015
OptimalResult = fmincon(@(x) ObjFun(x,NumConnections,NodesToSearchFrom), x0, [], [], [], [], [], [], @SideConstraints, options)
Provided that NumConnections and NodesToSearchFrom are static for any one optimization.
  2 Comments
Martha
Martha on 29 Nov 2015
Thank you Walter,
Its the first time I'm trying to set up an optimization routine, so I'm a little bit lost. I tried the line that you wrote, and now I don't have any warnings regarding the Objective Function, but I do have the same warning for the Constraints (i.e. that I don't have enough input arguments).
Why does this happened?, it is because I'm not calling properly the constraints in the line with the fmincon?, or because the way I'm setting the constraints in the constraints function?
Best,
Martha
Walter Roberson
Walter Roberson on 29 Nov 2015
OptimalResult = fmincon(@(x) ObjFun(x, NumConnections, NodesToSearchFrom), x0, [], [], [], [], [], [], @(x) SideConstraints(x, NumConnections, NumInterNodes, UnfeasibleNodeArea, LowerBound, UpperBound, ConnectionCentre), options)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!