Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 工程数学软件 > MATLAB论坛
MATLAB论坛 一切MATLAB相关问题在此讨论。
回复
 
主题工具 显示模式
旧 2009-10-08, 15:35   #1
moyuecha
初级会员
 
注册日期: 2008-09-01
年龄: 40
帖子: 2
声望力: 0
moyuecha 正向着好的方向发展
默认 求助 关于保存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


先 多谢啦!!
moyuecha 当前离线   回复时引用此帖
回复


发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛启用 表情符号
论坛启用 [IMG] 代码
论坛禁用 HTML 代码



所有时间均为北京时间。现在的时间是 15:19


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