More detailed output function in optimization

조회 수: 1 (최근 30일)
Mohammad Shojaei Arani
Mohammad Shojaei Arani 2022년 8월 2일
댓글: Mohammad Shojaei Arani 2022년 8월 2일
Hello,
I think I have a simple question but found it difficult to fix it myself.
In doing the optimization we can have 'our' output function. The following represents roughly my code and my output function:
Extra_param = A number;
options=optimoptions('fmincon','OutputFcn',@myoutput,'StepTolerance',10^(-8));
fmincon(cost,x0,[],[],[],[],lb,ub,[],options);
function stop = myoutput(x,optimvalues,state);
stop = false;
if isequal(state,'iter')
disp(num2str(x));
end
end
I would like the output function to dsplay me another parameter called 'Extra_param' which is not related to the optimum values or optimum state. It is just an extra parameter (and has nothing to do with the optimization problem being solved). so, I would like something like bellow:
function stop = myoutput(x,optimvalues,state,Extra_param);
stop = false;
if isequal(state,'iter')
disp(num2str(x));
disp(num2str(Extra_param));
end
end
But, unfortunately I get the following error message:
Unrecognized function or variable 'Extra_param'.
  댓글 수: 2
Walter Roberson
Walter Roberson 2022년 8월 2일
@myoutput
should become
@(x,op,st)myoutput(x,op,st,Extra_param)
This assumes that the value is known before you start optimization
Mohammad Shojaei Arani
Mohammad Shojaei Arani 2022년 8월 2일
Yes Walter. Great!
Thanks man!

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Problem-Based Optimization Setup에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by