声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 830|回复: 2

[编程技巧] 求助——求高手帮忙看一下程序!

[复制链接]
发表于 2007-4-3 16:51 | 显示全部楼层 |阅读模式

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

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

x
funf='f=0.5*70^2*x(2)+0.5*(70-x(3))^2*x(1);';
fung='g=[-1584/1225*x(2)-7352575626214095/18446744073709551616*x(1)*(70-x(3))^2-11/49000*x(1)*(70-x(3))*x(3)+11/7000*(70-x(3))*x(1)+11/10;(-56448*x(2)-87/5*x(1)*(70-x(3))^2-49/5*x(1)*(70-x(3))*x(3)+343/5*(70-x(3))*x(1))/((70-x(3))*x(1)+70*x(2))-(2058*x(1)*(70-x(3))*x(3)*x(2)+147/5*x(1)*(70-x(3))^2*((35/3-1/6*x(3))*x(1)+35*x(2))+367500.0*x(2)*((-35+1/2*x(3))*x(1)+35/3*x(2))+75.0*x(1)*(70-x(3))^2*((-35/3+1/6*x(3))*x(1)+35*x(2))-6*(343/30*(70-x(3))*x(1)+2401/3*x(2))*((70-x(3))*x(1)+70*x(2))-3361400.0000000000000000000000000)/((70-x(3))*x(1)+70*x(2))^2;(-288/25*x(2)*x(3)^2-49/5*x(1)*(70-x(3))*x(3))/x(3)/x(2)-(11.520000000000000000000000000000*x(2)^2*x(3)^3+294/5*x(1)*(70-x(3))*x(3)*(1/2*x(3)*x(2)+(35-1/2*x(3))*x(1))-9.7999999999999999999999999999998*x(3)^3)/x(3)^2/x(2)^2];';
>>fun=[funf fung];
>>x0=[0.15,0.65,40];
>>x=fmincon(fun,x0,[0 0.6 0],[0.2 0.8 70]);
是一个优化的题目,我的fmincon这个函数好像用错了,但是帮助里好像没有说非线性的情况,我不会用,请高手赐教!谢谢了!
回复
分享到:

使用道具 举报

发表于 2007-4-4 09:14 | 显示全部楼层
问题较多:
1. funf fung写法明显不对,请仔细检查;
2. 建议将二者存为函数后再调用;
3. help fmincon, 明显有语法X=FMINCON(FUN,X0,A,B,Aeq,Beq,LB,UB,NONLCON),可参考之.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
先自己试试,若还有问题,再来讨论.

评分

1

查看全部评分

 楼主| 发表于 2007-4-4 10:48 | 显示全部楼层
我后来按照X=FMINCON(FUN,X0,A,B,Aeq,Beq,LB,UB,NONLCON)试过了,可是警告说我设置的非线性约束只有一个,我不知道怎么通过options设置。
function y=myfun(x)
y=0.5*70^2*x(2)+0.5*(70-x(3))^2*x(1);

function [c,ceq]=mycon(x)
c(1)=-1584/1225*x(2)-7352575626214095/18446744073709551616*x(1)*(70-x(3))^2-11/49000*x(1)*(70-x(3))*x(3)+11/7000*(70-x(3))*x(1)+11/10;
c(2)=(-56448*x(2)-87/5*x(1)*(70-x(3))^2-49/5*x(1)*(70-x(3))*x(3)+343/5*(70-x(3))*x(1))/((70-x(3))*x(1)+70*x(2))-(2058*x(1)*(70-x(3))*x(3)*x(2)+147/5*x(1)*(70-x(3))^2*((35/3-1/6*x(3))*x(1)+35*x(2))+367500.0*x(2)*((-35+1/2*x(3))*x(1)+35/3*x(2))+75.0*x(1)*(70-x(3))^2*((-35/3+1/6*x(3))*x(1)+35*x(2))-6*(343/30*(70-x(3))*x(1)+2401/3*x(2))*((70-x(3))*x(1)+70*x(2))-3361400.0000000000000000000000000)/((70-x(3))*x(1)+70*x(2))^2;
c(3)=(-288/25*x(2)*x(3)^2-49/5*x(1)*(70-x(3))*x(3))/x(3)/x(2)-(11.520000000000000000000000000000*x(2)^2*x(3)^3+294/5*x(1)*(70-x(3))*x(3)*(1/2*x(3)*x(2)+(35-1/2*x(3))*x(1))-9.7999999999999999999999999999998*x(3)^3)/x(3)^2/x(2)^2;
ceq=[];
end

     x0=[0.15,0.65,40];
>> vlb=[0,0.6,0];
>> vub=[0.2,0.8,70];
>> x=fmincon('myfun',x0,[],[],[],[],vlb,vub,'mycon');


Warning: Divide by zero.
(Type "warning off MATLAB:divideByZero" to suppress this warning.)
> In D:\MATLAB6.5\work\mycon.m at line 4
  In D:\MATLAB6.5\toolbox\optim\private\nlconst.m at line 275
  In D:\MATLAB6.5\toolbox\optim\fmincon.m at line 458
Maximum number of function evaluations exceeded;
increase OPTIONS.MaxFunEvals
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

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

GMT+8, 2024-9-24 00:27 , Processed in 0.060284 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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