Show an expression on each iteration of the optimization
1 次查看(过去 30 天)
显示 更早的评论
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!
0 个评论
采纳的回答
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 个评论
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 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!