声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1128|回复: 1

[编程技巧] MATLAB 优化问题

[复制链接]
发表于 2009-3-23 20:28 | 显示全部楼层 |阅读模式

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

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

x
MATLAB 优化问题程序如下:
function f1=yjj(x)
global i r Tor Toc Tr Tc tr tc Cg tg1 Qc_n
f1=(Cinv(x)+Crun(x))/(x(1)+x(7)*(1-Tor/Tr)+x(8)*(Toc/Tc-1))

function f14=XLtur(x)
f14=0.2166+2.20906*10^(-5)*x(5)-1.02049*10^(-9)*x(5)^2

function f19=rdb(x)
f19=2.35-2.25*10^(-4)*x(5)+1.35*10^(-8)*x(5)^2

function f15=Mg(x)
global r
f15=3600/(XLtur(x)*r)

function f6=Ctur(x)
global i
f6=(i+2.49)*(204200+330*x(5))

function f10=Ctrs(x)
f10=1550*x(1)

function f12=Cspp(x)
f12=1000*x(10)

function f17=Cs1(x)
global tr tc tg1
f17=0.06*(x(1)*(tr+tc)+x(3)*tg1)

function f4=Cs(x)
global Cr tr Cc tc Cg
f4=(Cr-Cg*0.1214)*x(9)*tr+(Cc-Cg*0.1214)*x(10)*tc

function f5=Crun(x)
global tr tc Cg tg1 r
f5=Cg*Mg(x)*x(1)*(tr+tc)+Cg*Mg(x)*x(3)*tg1+Cs1(x)

function f2=Cinv(x)
global i Qc_n
f2=x(6)*Ctur(x)+Cass(x)+251200+5330*Qc_n+Cexg(x)+Ctrs(x)+(Cclt(x)+Cspp(x))

function f3=Cinc(x)
global Ce te Cr tr Cc tc Cg tg1 Qr1 Cr1
f3=Ce*(x(1)*te+x(3)*tg1)+Cr*x(7)*tr+Cr1*Qr1*tg1+Cc*x(8)*tc+Cs(x)

function f9=Cexg(x)
f9=23*x(7)

function f11=Cclt(x)
f11=300*x(1)

function f7=Cass(x)
f7=980*x(1)

function f=myfun(x)
global i ic Ndep Nbud r Tor Toc Tr Tc Ce te Cr tr Cc tc Cg tg1 Qc_n Qr1 Cr1
f=Cinv(x)*yjj(x)/((Cinc(x)-Crun(x))*(((1+ic)^(Ndep-Nbud)-1)/(ic*(1+ic)^(Ndep-Nbud)))*1/(1+ic)^Nbud)

function[c,ceq]=mycon(x)
global Qr1
C=x(5)-Qr1/rdb(x);
Ceq=[x(1)-x(6)*x(5);x(7)-rdb(x)*x(1)];

clear
clc
global i ic Ndep Nbud cop r Tor Toc Tr Tc Ce te Cr tr Cc tc Cg tg1 Pe_n Qr_n Qc_n Qr1 Cr1
i=8.3; ic=0.1; Ndep=30; Nbud=1; cop=1.2; r=34888.6; Tor=270; Toc=303; Tr=338; Tc=280; Ce=0.58; te=6000;
Cr=0.258; tr=3440; Cc=0.1933; tc=2560; Cg=1.57; tg1=1040; Pe_n=2500; Qr_n=2815; Qc_n=3465; Qr1=957; Cr1=0.307;
x0=[1 1 1 1 1 1 1 1 1 1];
Aeq=[1 1 0 0 0 0 0 0 0 0;0 0 1 1 0 0 0 0 0 0;0 0 0 0 0 0 1 0 1 0;0 0 0 0 0 0 0 cop 0 cop];beq=[Pe_n;Pe_n;Qr_n;Qc_n];
options=optimset('largescale','off');
[x,fval]=fmincon(@myfun,x0,[],[],Aeq,beq,[],[],@mycon,options)
运行后出现如下的错误:
??? Error using ==> fmincon
FMINCON cannot continue because user supplied nonlinear constraint function
failed with the following error:
One or more output arguments not assigned during call to 'C:\MATLAB7\work\mycon.m (mycon)'.

Error in ==> Untitled at 9
[x,fval]=fmincon(@myfun,x0,[],[],Aeq,beq,[],[],@mycon,options)
不知道怎么解决,请高手帮忙解决一下,着急与惆怅中...
回复
分享到:

使用道具 举报

发表于 2009-3-24 18:54 | 显示全部楼层

回复 楼主 xiaosun 的帖子

楼主犯个小错误! 大小写混用!
function[c,ceq]=mycon(x)
global Qr1
C=x(5)-Qr1/rdb(x);
Ceq=[x(1)-x(6)*x(5);x(7)-rdb(x)*x(1)];

[ 本帖最后由 ChaChing 于 2009-3-24 18:55 编辑 ]
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

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

GMT+8, 2024-9-22 17:20 , Processed in 0.052153 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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