MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   MATLAB论坛 (https://www.labfans.com/bbs/forumdisplay.php?f=6)
-   -   [MATLAB混合编程] 求助 关于保存fmincon每个iteration的运行结果 (https://www.labfans.com/bbs/showthread.php?t=9832)

moyuecha 2009-10-08 15:35

求助 关于保存fmincon每个iteration的运行结果
 
在用fmincon编写程序,求一个方程f(x)得最优解。运算中出现99个iteration,想要plot 99个 iteration 中 x converge 到最优解的过程,不知如何实现呢?

在matlab center 看到一下解答,但运行后没有出现预期结果。
There is an undocumented global variable called OPT_STEP that you can
>check inside your objective function. When it has the value 1 you are
>about to finish (or just finished, I forget which) an iteration. For
>example, your objective function could look like this (roughly):
>
> function f = objective(x)
> global OPT_STEP
> f = <some calculation on x>
> if OPT_STEP == 1
> disp(x) % or whatever you want to do
> end


另外这是我写的一个fmincon的例子: 复制以上的做法但没有显示出每一步 iteration得x
function fff()

clear;
clc;


A=[-1,-2,-2;1,2,2]; b=[0;72];

x0 = [1000; 1000; 1000]; % Starting guess at the solution

[x,fval,EXITFLAG,OUTPUT] = fmincon(@myfun,x0,A,b)


function f = myfun(x)
global OPT_STEP
f = -x(1) * x(2) * x(3);
if OPT_STEP == 1
display(x) % or whatever you want to do
end


先 多谢啦!!


所有时间均为北京时间。现在的时间是 11:25

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.