24小时热门版块排行榜    

Znn3bq.jpeg
查看: 2811  |  回复: 9
当前只显示满足指定条件的回帖,点击这里查看本话题的所有回帖

zhanghui10

银虫 (小有名气)

[求助] 求助有关Matlab有约束非线性最优化问题

我现在进行一个有约束的非线性最优化,但是变量较多,我写了下面一段程序
定义目标函数
function f=myfun1(x)
ds=4.77;dr=2.36;
f=(ds*x(20)-dr*x(10))/(ds*x(20)+dr*x(10))-(x(1)-x(11))/(x(1)+x(11))
定义约束
function [c,ceq]=mycon1(x)
dr=4.77;dr=2.36;b=0.001;m=0.5.*b;w0=60.4;o0=100;f=41.7;
c=[w1.*dr.*x(1)+o1.*x(1)-o2.*x(2);w2.*dr.*x(2)+o2.*x(2)-w1.*dr.*x(1)-o3.*x(3);w3.*dr.*x(3)+o3.*x(3)-w2.*dr.*x(2)-o3.*x(4);w4.*dr.*x(4)+o4.*x(4)-w3.*dr.*x(3)-o3.*x(5);w5.*dr.*x(5)+o5.*x(5)-w4.*dr.*x(4)-o6.*x(6)-f.*m;w6.*dr.*x(6)+o6.*x(6)-w5.*dr.*x(5)-o7.*x(7);w7.*dr.*x(7)+o7.*x(7)-w6.*dr.*x(6)-o8.*x(8);w8.*dr.*x(8)+o8.*x(8)-w7.*dr.*x(7)-o9.*x(9);w9.*dr.*x(9)+o9.*x(9)-w8.*dr.*x(8)-o10.*x(10);w10.*dr.*x(10)+o10.*x(10)-w9.*dr.*x(9);w1.*ds.*x(11)+o1.*x(11)-o2.*x(12);w2.*ds.*x(12)+o2.*x(12)-w1.*ds.*x(11)-o3.*x(13);w3.*ds.*x(13)+o3.*x(13)-w2.*ds.*x(12)-o4.*x(14);w4.*ds.*x(14)+o4.*x(14)-w3.*ds.*x(13)-o5.*x(15);w5.*ds.*x(15)+o5.*x(15)-w4.*ds.*x(14)-o6.*x(16)-f.*m;w6.*dr.*x(16)+o6.*x(16)-w5.*dr.*x(15)-o7.*x(17);w7.*dr.*x(17)+o7.*x(17)-w6.*dr.*x(16)-o8.*x(18);w8.*dr.*x(18)+o8.*x(18)-w7.*dr.*x(17)-o9.*x(19);w9.*dr.*x(19)+o9.*x(19)-w8.*dr.*x(18)-o10.*x(20);w10.*dr.*x(20)+o10.*x(20)-w9.*dr.*x(19);w10.*dr.*x(20)+o1.*x(11)-f.*m;w10.*ds.*x(10)+o1.*x(1)-f.*m;w0+o0+f-w10-o1];
ceq=0;
主程序为:
b=0.001; x0=[0.1.*b;0.1.*b;0.1.*b;0.1.*b;0.1.*b;0.1.*b;0.1.*b;0.1.*b;0.1.*b;0.1.*b;0.1.*b;0.1.*b;0.1.*b;0.1.*b;0.1.*b;0.1.*b;0.1.*b;0.1.*b;0.1.*b;0.1.*b];
lb=zeros(20,1);
[x,fval,exitflag,output]=fmincon('myfun1',x0,[],[],[],[],lb,[],'mycon1')
但是运行结果为
??? Error using ==> fmincon
FMINCON cannot continue because user supplied objective function failed with the following error:
Error using ==> feval
Undefined command/function 'myfun1'.

请问这是啥原因啊,是不是程序写错啦啊。
回复此楼

» 猜你喜欢

» 本主题相关价值贴推荐,对您同样有帮助:

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

dbb627

荣誉版主 (著名写手)

【答案】应助回帖

保存为m文件后,点击run
CODE:
function AA
b=0.001;
x0=b*rand(1,20);
lb=zeros(20,1);
[x,fval,exitflag,output]=fmincon(@myfun1,x0,[],[],[],[],lb,[],@mycon1)

function f=myfun1(x)
ds=4.77;dr=2.36;
f=(ds*x(20)-dr*x(10))/(ds*x(20)+dr*x(10))-(x(1)-x(11))/(x(1)+x(11))

function [c,ceq]=mycon1(x)
ds=4.77;dr=2.36;b=0.001;m=0.5.*b;w0=60.4;o0=100;f=41.7;
w1=1;w2=2;w3=3;w4=4;w5=5;w6=6;w7=7;w8=8;w9=9;w10=10;%输入w1-w10的值
o1=1;o2=2;o3=3;o4=4;o5=5;o6=6;o7=7;o8=8;o9=9;o10=10;%输入o1-o10的值
c=[w1.*dr.*x(1)+o1.*x(1)-o2.*x(2);w2.*dr.*x(2)+o2.*x(2)-w1.*dr.*x(1)-o3.*x(3);...
    w3.*dr.*x(3)+o3.*x(3)-w2.*dr.*x(2)-o3.*x(4);w4.*dr.*x(4)+o4.*x(4)-...
    w3.*dr.*x(3)-o3.*x(5);w5.*dr.*x(5)+o5.*x(5)-w4.*dr.*x(4)-o6.*x(6)-...
    f.*m;w6.*dr.*x(6)+o6.*x(6)-w5.*dr.*x(5)-o7.*x(7);w7.*dr.*x(7)+o7.*x(7)-...
    w6.*dr.*x(6)-o8.*x(8);w8.*dr.*x(8)+o8.*x(8)-w7.*dr.*x(7)-o9.*x(9);w9.*dr.*x(9)+...
    o9.*x(9)-w8.*dr.*x(8)-o10.*x(10);w10.*dr.*x(10)+o10.*x(10)-w9.*dr.*x(9);...
    w1.*ds.*x(11)+o1.*x(11)-o2.*x(12);w2.*ds.*x(12)+o2.*x(12)-w1.*ds.*x(11)-...
    o3.*x(13);w3.*ds.*x(13)+o3.*x(13)-w2.*ds.*x(12)-o4.*x(14);w4.*ds.*x(14)+...
    o4.*x(14)-w3.*ds.*x(13)-o5.*x(15);w5.*ds.*x(15)+o5.*x(15)-w4.*ds.*x(14)-...
    o6.*x(16)-f.*m;w6.*dr.*x(16)+o6.*x(16)-w5.*dr.*x(15)-o7.*x(17);...
    w7.*dr.*x(17)+o7.*x(17)-w6.*dr.*x(16)-o8.*x(18);w8.*dr.*x(18)+o8.*x(18)-...
    w7.*dr.*x(17)-o9.*x(19);w9.*dr.*x(19)+o9.*x(19)-w8.*dr.*x(18)-o10.*x(20);...
    w10.*dr.*x(20)+o10.*x(20)-w9.*dr.*x(19);w10.*dr.*x(20)+o1.*x(11)-...
    f.*m;w10.*ds.*x(10)+o1.*x(1)-f.*m;w0+o0+f-w10-o1];
ceq=[];

The more you learn, the more you know, the more you know, and the more you forget. The more you forget, the less you know. So why bother to learn.
3楼2011-11-22 23:18:39
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
查看全部 10 个回答

dbb627

荣誉版主 (著名写手)

【答案】应助回帖

你的约束条件里面w1-w10 和o1-o10的值没有定义值
The more you learn, the more you know, the more you know, and the more you forget. The more you forget, the less you know. So why bother to learn.
2楼2011-11-22 23:10:28
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

zhanghui10

银虫 (小有名气)

w1-w10,o1-o10不能通过w0,o0与x(1),x(10)的关系输出嘛。
4楼2011-11-23 08:34:24
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

dbb627

荣誉版主 (著名写手)

【答案】应助回帖

引用回帖:
4楼: Originally posted by zhanghui10 at 2011-11-23 08:34:24:
w1-w10,o1-o10不能通过w0,o0与x(1),x(10)的关系输出嘛。

又不是解方程 ,怎么输出约束条件里的参数
The more you learn, the more you know, the more you know, and the more you forget. The more you forget, the less you know. So why bother to learn.
5楼2011-11-23 08:52:05
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 0702物理学学硕299求调剂 +6 祁柒连 2026-04-06 6/300 2026-04-10 11:10 by Roomoo
[考研] 347材料专硕求调剂 +19 zj8215216 2026-04-06 19/950 2026-04-10 09:36 by 690616278
[考研] 求调剂288 +5 ioodiiij 2026-04-10 6/300 2026-04-10 09:10 by potato妹
[考研] 070300化学学硕311分求调剂 +12 梁富贵险中求 2026-04-04 14/700 2026-04-10 08:07 by kangsm
[考研] 工科273调剂 +5 X1999 2026-04-09 6/300 2026-04-10 07:52 by 1753564080
[考研] 材料工程调剂 +12 小刘同学吖吖 2026-04-06 13/650 2026-04-09 17:07 by luoyongfeng
[考研] 一志愿鲁东大学071000生物学学硕初试分数276求调剂 +3 慕绝cc 2026-04-09 3/150 2026-04-09 09:57 by liuhuiying09
[考研] 材料调剂 +14 一样YWY 2026-04-06 14/700 2026-04-08 23:00 by 猪会飞
[考研] 软件工程求调剂22软工296分求调剂,接受跨调 +4 yangchen2017 2026-04-08 5/250 2026-04-08 21:56 by 土木硕士招生
[考研] 388求调剂 +6 四川王涛 2026-04-07 8/400 2026-04-08 00:17 by JourneyLucky
[考研] 318求调剂 +5 李青山山山 2026-04-07 5/250 2026-04-07 18:24 by 蓝云思雨
[考研] 生物工程求调剂 +13 喜欢还是不甘心 2026-04-05 13/650 2026-04-07 16:55 by Ecowxq666!
[考研] 一志愿北京化工085600 310分求调剂 +20 0856材料与化工3 2026-04-04 22/1100 2026-04-07 15:14 by 上岸快快
[考研] 085100建筑学 寻求跨专业调剂 一志愿南大294分 校级省级国家级奖项若干 踏实肯干 +3 1021075758 2026-04-06 4/200 2026-04-07 09:23 by 蓝云思雨
[考研] 考研调剂 +7 15615482637 2026-04-04 7/350 2026-04-06 22:56 by chenzhimin
[考研] 338求调剂 +4 我想上岸ii 2026-04-05 4/200 2026-04-06 21:04 by 木子君1218
[考研] 22408 总分320,一篇论文二作,两个国三,求调剂 +3 Leomulufu 2026-04-04 5/250 2026-04-05 19:04 by chongya
[考研] 288求调剂,一志愿华南理工大学071005 +6 ioodiiij 2026-04-04 6/300 2026-04-05 10:09 by guoweigw
[考研] 083200 333求调剂 +3 十二!! 2026-04-04 3/150 2026-04-05 08:28 by barlinike
[考研] 一志愿双非085502,267分,过四级求调剂 +3 再忙也要吃饭啊 2026-04-03 3/150 2026-04-04 05:03 by gswylq
信息提示
请填处理意见