Show an expression on each iteration of the optimization

조회 수: 1 (최근 30일)
Jurgen
Jurgen 2014년 9월 29일
댓글: Alan Weiss 2014년 10월 1일
Hello,
I'm using "lsqnonlin" to optimize a function and would like to show a expression, important for my problem, in each iteration. This expression depends on the optimization variables, therefore will change with each iteration. I understand that I can do this with OutputFcn, but I failed to understand how. I think it should not be complicated, please help!
The indicator is: (z(1)*z(2)+6)/z(4)+z(5)*z(6)
Thanks in advance!

채택된 답변

Alan Weiss
Alan Weiss 2014년 9월 29일
Write a function named Jurgenoutput consisting of the following:
function stop = Jurgenoutput(z,optimValues,state)
stop = false;
indicator = (z(1)*z(2)+6)/z(4)+z(5)*z(6);
disp(indicator)
Include the output function in your solver call as follows:
options = optimoptions('lsqnonlin','OutputFcn',@Jurgenoutput);
x = lsqnonlin(fun,x0,lb,ub,options)
Alan Weiss
MATLAB mathematical toolbox documentation
  댓글 수: 4
Jurgen
Jurgen 2014년 10월 1일
Apparently I can not use any variable defined outside the output function, I want to do the following and can not.
function stop = Jurgenoutput(z,optimValues,state)
stop = false;
indicator = (z(1)*z(2)+6)/z(4)+z(5)*z(6)*g1c;
disp(indicator)
where g1c was defined outside Jurgenoutput and is a constant number.
Alan Weiss
Alan Weiss 2014년 10월 1일
You need to look at how to pass extra parameters. Probably, a nested function would pass g1c successfully.
Alan Weiss
MATLAB mathematical toolbox documentation

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

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