An error due to output function

조회 수: 4 (최근 30일)
Mohammad Shojaei Arani
Mohammad Shojaei Arani 2022년 8월 25일
댓글: Mohammad Shojaei Arani 2022년 8월 25일
Hellow,
I am getting an error message which I did not expect (I explain why). I am solving an optimization problem. When I use fmincon no error appears. But, when I use patternsearch I get an error message, so this is really unexpected. The following are relevant parts of my code:
This works and I get no error message:
options=optimoptions('fmincon','OutputFcn',@(x,A,state)myoutput_Spline(x,A,state,dt,M),'StepTolerance',10^(-12),'FunctionTolerance',10^(-12),'MaxFunEvals',10^8,'MaxIter',10^8);
fmincon(cost,par0,[],[],[],[],lb,ub,[],options);
But this does not work and I get an error message:
options=optimoptions('patternsearch','UseParallel',UseParallel,'Display','iter','OutputFcn',@(x,A,state)myoutput_Spline(x,A,state,dt,M));
patternsearch(cost,par0,[],[],[],[],lb,ub,[],options)
Error using myoutput_Spline
Too many output arguments.
My output function is:
function stop = myoutput_Spline(x,A,state,dt,M)
stop = false;
if isequal(state,'iter')
par=x;
par(1:M)=x(1:M)./dt;
par(M+1:end)=x(M+1:end)./sqrt(dt);
disp('Estimated parameters : ');
disp(num2str(par));
disp(['Approximate value of objective function (negative of sum of log-likelihoods) : ' num2str(A.fval)]);
end
end
I have no idea what the hell is this!!!
Thanks for your help

채택된 답변

Walter Roberson
Walter Roberson 2022년 8월 25일
Your output function must have the following calling syntax:
[stop,options,optchanged] = myfun(optimvalues,options,flag)
However, your outputfcn only has a single output.
The function definition line of the output function or plot function has the following form:
stop = outfun(x,optimValues,state)
You should be emitting all three outputs; fmincon should ignore the extra outputs.

추가 답변 (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