声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1880|回复: 3

[编程技巧] fmincon - Undefined function or variable

[复制链接]
发表于 2009-4-10 10:31 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
clear
x0=[1,1,1,1,1,1];
lb=[1,1,1,1,1,1];
ub=[32,32,32,32,32,32];
options=optimset('largescale','off','display','iter');
[x,fval,exitflag,output]=fmincon(@objfun,x0,[],[],[],[],lb,ub,@confun,options)

function f=objfun(x);
f=x1+x2+x3+x4+x5+x6;

function [c ce]=confun(x)
c=[255*2^-x(1)+255*2^-x(2)+255*2^-x(3)+2^-x(4)+2^-x(5)+2^-x(6)-0.5];
ce=[];
这样求的的解怎么不对啊?
请高手指教。

[ 本帖最后由 ChaChing 于 2009-4-21 20:10 编辑 ]
回复
分享到:

使用道具 举报

发表于 2009-4-10 15:32 | 显示全部楼层
建议看下本版规则! 求助完整格式:出错代码和出错提示
 楼主| 发表于 2009-4-21 17:27 | 显示全部楼层

回复 沙发 ChaChing 的帖子

呵呵!已经解决了!谢谢!
发表于 2009-4-21 20:10 | 显示全部楼层
我来补齐出错代码, 如下
??? Error using ==> fmincon
FMINCON cannot continue because user supplied objective function failed with the following error:
Undefined function or variable 'x1'.

Error in ==> zzz at 6
[x,fval,exitflag,output]=fmincon(@objfun,x0,[],[],[],[],lb,ub,@confun,options)

大家时间都有限, 若能给齐完整资讯, 别人较容易了解状况并回覆!
发问者亦能以最快的速度解决问题, 天助自助者!
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-9-22 15:41 , Processed in 0.059219 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表