Can you help me with the output of my optimizer?

조회 수: 1 (최근 30일)
Jorge Armando Vazquez
Jorge Armando Vazquez 2021년 6월 1일
편집: Walter Roberson 2021년 6월 3일
I have this program from
par0 = [0.1,0.0001,100];% initial values
history = [];
fun_objetivo = @(par,pfrac)FunObjetivo(par);
options = optimset('MaxIter',3000,'MaxFunEvals',3000,'Display','iter','OutputFcn', @myoutput);
%We use here the Nelder-Mead method
par_optimos = fminsearch(fun_objetivo, par0, options);
function stop = myoutput(par_optimos,optimvalues,state);
stop = false;
if isequal(state,'iter')
history = [history;par_optimos];
end
end
but I can´t make it give me the value of my vector par_optimos for each iteration, can someone help me?

답변 (2개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021년 6월 1일
You'd need define a math formulation of fun_objetivo = @(par,pfrac)FunObjetivo(par);
Once it is done, you can run via loop iteration, i.e.: for ... end

Alan Weiss
Alan Weiss 2021년 6월 2일
Use this example as a guide: Example of a Nested Output Function.
Alan Weiss
MATLAB mathematical toolbox documentation
  댓글 수: 2
Jorge Armando Vazquez
Jorge Armando Vazquez 2021년 6월 3일
That is what I used
fun_objetivo = @(par,pfrac)FunObjetivo(par);
history=[];
options = optimset('MaxIter',3000,'MaxFunEvals',3000,'Display','iter','OutputFcn', @myoutput);;%,'PlotFcns',@optimplotfval);
%We use here the Nelder-Mead method
par_optimos = fminsearch(fun_objetivo, par0, options);
function stop = myoutput(par_optimos,optimvalues,state);
stop = false;
if isequal(state,'iter')
history = [history;par_optimos];
end
end
but there is error with
Error in Main_optim_15_05_21>myoutput (line 15)
history = [history;par_optimos];
Walter Roberson
Walter Roberson 2021년 6월 3일
편집: Walter Roberson 2021년 6월 3일
You did not nest the function like suggested.
history = do_the_work;
function hist = do_the_work()
fun_objetivo = @(par,pfrac)FunObjetivo(par);
history=[];
options = optimset('MaxIter',3000,'MaxFunEvals',3000,'Display','iter','OutputFcn', @myoutput);;%,'PlotFcns',@optimplotfval);
%We use here the Nelder-Mead method
par_optimos = fminsearch(fun_objetivo, par0, options);
hist = history;
function stop = myoutput(par_optimos,optimvalues,state);
stop = false;
if isequal(state,'iter')
history = [history;par_optimos];
end
end
end

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

카테고리

Help CenterFile Exchange에서 Optimization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by