How to formulate this constrained function in Matlab?

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

Respuestas (2)

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
Torsten el 26 de Abr. de 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.

Preguntada:

el 26 de Abr. de 2016

Respondida:

el 26 de Abr. de 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by