How to formulate this constrained function in Matlab?
Ältere Kommentare anzeigen
I got this constrained function and trying to use Matlab to solve it. $1/2x^T XAXx:IIxII^2=1$ T is for transpose. , where A is a symmetric nxn matrix and X is the diagonal matrix with element x_i. Also, IIxII denotes the Euclidean norm of a vector x. Please I need someone to help me of how to formulate this constrained function in Matlab. THANKS ALOT
Antworten (2)
Walter Roberson
am 26 Apr. 2016
function r = obj(xunscaled, A)
x = (xunscaled)./norm(xunscaled);
X = diag(x);
obj = 1/2 * x.' * X * A * X * x;
end
Together with
A = whatever;
n = size(A,1);
conA = [];
conb = [];
conAeq = [];
conbeq = [];
lb = -1 * ones(1,n);
ub = 1 * ones(1,n);
xbest = fmincon(@(xunscaled) obj(xunscaled, A), conA, conb, conAeq, conbeq, lb, ub);
xbest_scaled = xbest ./ norm(xbest);
I transformed it from having a non-linear constraint into one that did not, by normalizing the vector inside the function. I use -1 and +1 as the constraints because in your unscaled x it is not possible for any component of x to exceed +/- 1 as that would make the magnitude too large.
Torsten
am 26 Apr. 2016
Setting y(i) = x(i)^2, the problem is equivalent to
min: y'*A*y
s.c. sum(y(i))=1
y(i)>=0.
You can use MATLAB's "quadprog" to solve.
Best wishes
Torsten.
Kategorien
Mehr zu Choose a Solver finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!