主题: [MATLAB基础] 求助!求助。。。
查看单个帖子
旧 2011-04-16, 07:08   #2
anbcjys
高级会员
 
注册日期: 2008-09-14
年龄: 43
帖子: 351
声望力: 24
anbcjys 正向着好的方向发展
默认 回复: 求助!求助。。。

引用:
作者: jy02368333 查看帖子
我在写论文的时候遇到了一个问题,怎么解都解决不了,能不能麻烦大家帮忙一下,谢谢了。。
我求解是马科维茨方程,用matlab求出。。。
是一个二次规划。
min σ_w=w'T Vw
s.t. w'T e=w1+w2+⋯+wn=1
w'T μ=w1 *μ1+w2* μ2+⋯+wn*μn=μ

我最开始用quadprog做,程序如下:
H=[0.000784,0.000463,0.000672,0.000121,0.000286;0.000463,0.000545,0.000472,0.000088,0.000183;0.000672,0.000472,0.000986,0.000178,0.000288;0.000121,0.000088,0.000178,0.000055,0.000070;0.000286,0.000183,0.000288,0.000070,0.000238]
Aeq =[0.0095,0.0041,0.0083,0.0019,0.0041;1,1,1,1,1]
beq=[0.025;1]
f=[0,0,0,0,0]'
lb=zeros(5,1)
x=quadprog(H,f,[],[],Aeq,beq,lb)
结果matlab报错:Warning: Large-scale method does not currently solve this problem formulation,
switching to medium-scale method.
> In quadprog at 236
Exiting: the constraints are overly stringent;
no feasible starting point found.

我不能求出约束解。


后来,我就指定函数:
fun1=x'Hx
然后用fmincon做。

w0=[0.2;0.2;0.2;0.2;0.2];
w=[w1;w2;w3;w4;w5];
e=[0.000784,0.000463,0.000672,0.000121,0.000286;0.000463,0.000545,0.000472,0.000088,0.000183;0.000672,0.000472,0.000986,0.000178,0.000288;0.000121,0.000088,0.000178,0.000055,0.000070;0.000286,0.000183,0.000288,0.000070,0.000238]
objfun=w'*e*w;
r =[0.0095,0.0041,0.0083,0.0019,0.0041]'
A=[];
b=[];
Aeq=[0.0095,0.0041,0.0083,0.0019,0.0041;1 1 1 1 1];
beq=[0.025;1];
lb=[0 0 0 0 0];
[x,fval]=fmincon(@myfun1,w0,[],[],Aeq,beq,lb)
结果
matlab还是报错FMINCON cannot continue because user supplied objective function failed with the following error:
Undefined function or variable 'H'.

大家能帮忙下么。。。
myfun1里面的H没有定义
__________________
qq604443022
anbcjys 当前离线   回复时引用此帖