Minimizing a function
21 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (3)
Cédric Devivier
le 6 Sep 2011
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 commentaires
Teja Muppirala
le 7 Sep 2011
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)
4 commentaires
Voir également
Catégories
En savoir plus sur Get Started with Optimization Toolbox dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!