24小时热门版块排行榜    

查看: 318  |  回复: 1

qiaoye32803

新虫 (初入文坛)

[求助] 函数调用

这是我的目标函数,里面有随机生成数:
function opforpaper=lq_paper(x)
syms theta;
mu_ra=0.0645;
mu_rb=0.0889;
mu_rc=0.043;
sigma_ra=0.008;
sigma_rb=0.07;
sigma_rc=0.004;

for i=1:100                    
f_1(i)=cos(theta)*(x(1)+x(3)*normrnd(0,1)+normrnd(mu_rb,sigma_rb)*cos(unifrnd(0,2*pi))-normrnd(mu_ra,sigma_ra)*cos(unifrnd(0,2*pi)))+sqrt((x(2)+x(4)*normrnd(0,1)+normrnd(mu_rc,sigma_rc)*cos(unifrnd(0,2*pi))).^2-(x(1)+x(3)*normrnd(0,1)+normrnd(mu_rb,sigma_rb)*cos(unifrnd(0,2*pi))-normrnd(mu_ra,sigma_ra)*sin(theta)).^2);
f_2(i)=cos(theta+0.0063)*(x(1)+x(3)*normrnd(0,1)+normrnd(mu_rb,sigma_rb)*cos(unifrnd(0,2*pi))-normrnd(mu_ra,sigma_ra)*cos(unifrnd(0,2*pi)))+sqrt((x(2)+x(4)*normrnd(0,1)+normrnd(mu_rc,sigma_rc)*cos(unifrnd(0,2*pi))).^2-(x(1)+x(3)*normrnd(0,1)+normrnd(mu_rb,sigma_rb)*cos(unifrnd(0,2*pi))-normrnd(mu_ra,sigma_ra)*sin(theta+0.0063)).^2);
f3(i)=abs(f_1(i)-f_2(i));
end
opforpaper=mean(f3);
下面的是约束,
function [c,ceq]=consfun(x)
M=384;
c=[(M*sqrt(M^2+f3^2)-M)/(2*sqrt(M^2+f3^2))-0.05;f3*M/(2*sqrt(M^2+f3^2))-0.5];
ceq=[];
下面的是所用的计算函数:
clear
x0=[50,335,0.005,0.05];
lb=[45,330,0.002,0.007];
ub=[55,340,0.02,0.07];
options=optimset('largescale','off','Algorithm','active-set');
[x,fval]=fmincon('lq_paper',x0,[],[],[],[],lb,ub,'consfun',options)
现在有个问题:在约束中的f3必须是目标函数中生成的那个f3,因为目标函数中的f3含有随机数,请问哪位大神能帮我下,在约束中调用目标函数中的那个f3!
回复此楼
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

csgt0

荣誉版主 (著名写手)

彩色挂图

【答案】应助回帖

感谢参与,应助指数 +1
用全局变量试试,应该可以的吧
showmethemoney
2楼2012-11-20 12:01:26
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 qiaoye32803 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考博] 澳大利亚 Murdoch University 全奖博士招生(3个名额)地质化工冶金领域 +21 AI8RaGaPaSCR 2026-08-07 22/1100 2026-08-13 19:15 by GOa33HKKemiO
[基金申请] 静等基金结果 +8 gjjjzhong 2026-08-10 21/1050 2026-08-13 17:56 by 且听虎啸
[基金申请] FileCode能看出啥? +10 要乐观耀哥 2026-08-10 28/1400 2026-08-13 17:51 by 医学老男孩
[基金申请] 有时候,自然基金真的不能太认真 (我的申报经验) +4 majunge000 2026-08-11 6/300 2026-08-13 16:50 by 四季常青藤
[基金申请] 重要来源:本周末出结果 +10 瞬息宇宙 2026-08-12 10/500 2026-08-13 15:46 by likettle
[基金申请] Filecode 又变了,巨变 +3 WH3796 2026-08-12 4/200 2026-08-13 14:13 by 小木虫6752397
[基金申请] 关于Filecode分析方法 +9 majunge000 2026-08-10 11/550 2026-08-13 10:40 by ZH远山
[基金申请] 应该是93bebmhtak前后十一个字符比较关键 +22 Lanmanbaby 2026-08-09 36/1800 2026-08-12 22:50 by sdfapple719
[基金申请] 好奇怪的filecode +5 布布和一二 2026-08-08 6/300 2026-08-12 16:11 by 云上清扬
[论文投稿] 职称评审,求友友推荐见刊最快的期刊 +4 工厂打螺丝 2026-08-08 4/200 2026-08-12 09:18 by hansi2025
[基金申请] 奇怪,两个人的filecode固定段从头到尾一模一样 +7 布布和一二 2026-08-10 10/500 2026-08-12 09:12 by 布布和一二
[基金申请] 综述论文作为代表作会不会影响评审专家的印象分? +11 yufeiwaner 2026-08-09 13/650 2026-08-12 08:17 by yufeiwaner
[基金申请] 帮忙看看fileCode +7 wwncly 2026-08-10 13/650 2026-08-11 19:36 by 冰心玉壶晴
[基金申请] 为什么网上很多人说本周 12号出结果 +6 瞬息宇宙 2026-08-10 7/350 2026-08-11 19:25 by Tide man
[基金申请] 什么时候出结果,有咨询渠道??? +3 Tide man 2026-08-11 3/150 2026-08-11 17:54 by kudofaye
[基金申请] 确定了,国自然21号放榜 +6 布布和一二 2026-08-10 7/350 2026-08-10 19:15 by 2000zf36392
[基金申请] 据悉今年马上要出结果了 +7 瞬息宇宙 2026-08-10 8/400 2026-08-10 12:42 by Vivilian
[基金申请] 2026国自然放榜时间 +9 布布和一二 2026-08-08 9/450 2026-08-10 11:22 by xxxx2020
[基金申请] 关于filecode +4 布布和一二 2026-08-07 7/350 2026-08-07 22:55 by zhanghaozhu
[基金申请] 化学口download_prp&fileCode的固定段好像这几天一直没变,有变的大神么? +3 Tide man 2026-08-07 4/200 2026-08-07 22:39 by Tide man
信息提示
请填处理意见