Find the theta1 and theta2 values that maximizes obj8Run
1 次查看(过去 30 天)
显示 更早的评论
Hello everyone! I need some help to maximize my obj8Run function
My code is the following:
i=121:480;
MRn4=w4tilda.*MR4
mMRn4=mean(MRn4)
Sn4=cov(MRn4)
SRn4=M4/S4
Kp=(ret(i-4,1:10)+1).*(ret(i-3,1:10)+1).*(ret(i-2,1:10)+1).*(ret(i-1,1:10)+1)
Kp=Kp-1
Kp=normalize(Kp)
Lp= (bm(i-4,1:10)+1).*(bm(i-3,1:10)+1).*(bm(i-2,1:10)+1).*(bm(i-1,1:10)+1)
Lp=Lp-1;
Lp=normalize(Lp);
mlp=mean(Lp)
objSRun = @(theta) -((1+theta(1,1).*mr4+theta(1,2).*mlp)/N).*mMRn4./sqrt(((1+theta(1,1).*mr4+theta(1,2).*mlp)/N)*Sn4*((1+theta(1,1).*mr4+theta(1,2).*mlp)/N)');
w0 = [0.2,0.3] % initial guess
lb = zeros(1, 2)
ub = 1.5*ones(1, 2)
sol = fmincon(objSRun, w0, [], [], [], [], lb, ub)
When i run it i gives me the following error: Error using fmincon (line 635)
Supplied objective function must return a scalar value.
How can i solve it???
Thanks in advance!
1 个评论
VBBV
2020-10-12
Try the objSRun supplying theta as
% if true
% code
% end
objSRun = @(theta)
((1+theta.*mr4+theta.*mlp)/N).*mMRn4./sqrt(((1+theta.*mr4+theta.*mlp)/N)*Sn4*((1+theta.*mr4+theta.*mlp)/N)')
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Systems of Nonlinear Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!