Error with FMINCON - Failure in initial user-supplied objective function evaluation
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Martha
le 28 Nov 2015
Commenté : Walter Roberson
le 29 Nov 2015
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
0 commentaires
Réponse acceptée
Walter Roberson
le 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 commentaires
Walter Roberson
le 29 Nov 2015
OptimalResult = fmincon(@(x) ObjFun(x, NumConnections, NodesToSearchFrom), x0, [], [], [], [], [], [], @(x) SideConstraints(x, NumConnections, NumInterNodes, UnfeasibleNodeArea, LowerBound, UpperBound, ConnectionCentre), options)
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Solver Outputs and Iterative Display dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!