필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
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

채택된 답변

Walter Roberson
Walter Roberson 2015년 11월 29일
OptimalResult = fmincon(@(x) ObjFun(x,NumConnections,NodesToSearchFrom), x0, [], [], [], [], [], [], @SideConstraints, options)
Provided that NumConnections and NodesToSearchFrom are static for any one optimization.
  댓글 수: 2
Martha
Martha 2015년 11월 29일
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 2015년 11월 29일
OptimalResult = fmincon(@(x) ObjFun(x, NumConnections, NodesToSearchFrom), x0, [], [], [], [], [], [], @(x) SideConstraints(x, NumConnections, NumInterNodes, UnfeasibleNodeArea, LowerBound, UpperBound, ConnectionCentre), options)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by