An error due to output function

2 Ansichten (letzte 30 Tage)
Mohammad Shojaei Arani
Mohammad Shojaei Arani am 25 Aug. 2022
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

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 25 Aug. 2022
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.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by