Error with FMINCON - Failure in initial user-supplied objective function evaluation
Afficher commentaires plus anciens
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
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Nonlinear Optimization dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!