Minimizing a function
6 次查看(过去 30 天)
显示 更早的评论
Hi,
I would like to minimize w'Hw, with respect to w, where w is a vector, and H is matrix.
And with the following constraint, (|w1|+|w2|+|w3| < 3), ie. the l1 norm of the weights vector is less that 3.
How can I do this in matlab?
Thanks
0 个评论
回答(3 个)
Cédric Devivier
2011-9-6
Hi,
Maybe the fminsearch function is enough ?
Something like that should work. Copy these two routines in a single m file.
function [w_min value] = minimize(w0,H)
[w_min value] = fminsearch(@(w) funtomini(w,H,w0) , w0);
end
function value = funtomini(w,H,w0)
if sum(abs(w))<3;
value = w'*H*w;
else
value = w0'*H*w0;
end
end
Find the minimum using this command
[w_min value] = minimize(w0,H);
Cheers,
Cédric
0 个评论
Teja Muppirala
2011-9-7
This is a quadratic programming problem, and can be solved very easily using QUADPROG. The only thing is correctly expressing the L1 constraint.
% Make some random H
H = rand(3,3);
H =H+H';
% Express the L1 constraint using matrices:
[X1,X2,X3] = ndgrid([-1 1]);
A = [X1(:) X2(:) X3(:)];
b = 3*ones(size(A,1),1);
% solve for x
x = quadprog(H,[],A,b)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Quadratic Programming and Cone Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!