全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 MATLAB等数学软件专版
3786 6
2012-08-03
悬赏 50 个论坛币 未解决
2N)Z]Z9]%[H)E}L{B_MPRPS.jpg
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2012-8-4 01:08:40
属于有约束的非线性规划问题
首先编写目标函数(取原函数的相反数):
function f=myfun(x)
f=-(2-0.9*x(1))*(200-10*x(2))*0.4*(1-(3-x(1))/(0.9*(x(2)-x(1))))...
    +0.9*x(1)*(200-10*x(2))*0.25*0.4^2*(1-(3-x(1))/(0.9*(x(2)-x(1))))^2;
再编写非线性约束函数:
function [c,ceq]=nl(x)
c=[];
ceq=(200-20*x(2)+10*x(1))*0.4^2*0.25*(0.9*(x(2)-x(1))-(3-x(1)))+0.2*0.4*(3-x(1));
最后写出线性约束:
A=[-1 -9];
b=-30;
写出上下界:
lb=[0;3];
ub=[20/9;20];
设定一个初始值:
x0=[2 4];
最后优化:
[x,fval,exitflag]=fmincon(@myfun,x0,A,b,[],[],lb,ub,@nl)
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-8-4 09:35:55
3生石 发表于 2012-8-4 01:08
属于有约束的非线性规划问题
首先编写目标函数(取原函数的相反数):
function f=myfun(x)
很感谢你的帮助……可是按照你的程序运行时,出现以下错误:
>> A=[-1 -9];
b=-30;
lb=[0;3];
ub=[20/9;20];
x0=[2 4];
[x,fval,exitflag]=fmincon(@myfun,x0,A,b,[],[],lb,ub,@nl)
Warning: Large-scale (trust region) method does not currently solve this type of problem,
switching to medium-scale (line search).
> In fmincon at 260
??? Error using ==> fmincon
FMINCON cannot continue because user supplied objective function failed with the following error:
Error using ==> feval
Undefined command/function 'myfun'.
不知道问题出在哪里……麻烦你了
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-8-4 10:11:31
myfun nl 两个函数分别存在两个m文件中,我运行没问题,祝你好运   
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-8-4 10:13:55
3生石 发表于 2012-8-4 10:11
myfun nl 两个函数分别存在两个m文件中,我运行没问题,祝你好运
你的matlab是哪个版本?还有,你算的结果是多少?非常感谢你哦
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-8-4 10:20:02
2012a最新版本的,我运行也有点问题,不知道是不是你的约束条件有问题,你再请教高人吧
Warning: The default trust-region-reflective algorithm does not solve problems with the
constraints you have specified. FMINCON will use the active-set algorithm instead. For
information on applicable algorithms, see Choosing the Algorithm in the documentation.
> In fmincon at 486

No feasible solution found.

fmincon stopped because the size of the current search direction is less than
twice the default value of the step size tolerance but constraints are not
satisfied to within the default value of the constraint tolerance.

<stopping criteria details>


x =

    2.2328    3.0746


fval =

   -0.0059


exitflag =

    -2
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群