How can I add constraints in a solution of a function?

8 visualizaciones (últimos 30 días)
gsourop
gsourop el 29 de Oct. de 2018
Comentada: Bruno Luong el 5 de Nov. de 2018
Hi everyone,
I would like to solve the following function by adding two constraints.
S=randn(6,6); y=randn(6,1); ONE = ones(6,1); rft=randn(1,1); K = randn(1,1);
x = inv(S)*(y- ONE*rft)*0.1/sqrt(K);
I would like to include 2 additional constraints, -1<sum(x)<2 . I am not sure how I should use fmincon.
  10 comentarios
Bruno Luong
Bruno Luong el 30 de Oct. de 2018
Yes, even the sqrt() might return complex result.
gsourop
gsourop el 30 de Oct. de 2018
I see. But is there a way to impose the additional constraints without solving the relationship arithmetically?

Iniciar sesión para comentar.

Respuesta aceptada

Bruno Luong
Bruno Luong el 30 de Oct. de 2018
Editada: Bruno Luong el 30 de Oct. de 2018
n = 6;
L = randn(n);
S = L'*L;
y = randn(n,1);
rft = randn(1,1);
su = 2;
sl = -1;
% T = V*V'
T = S/(0.1^2);
T = 0.5*(T+T');
[V,D] = eig(T);
V = V.*sqrt(diag(D)');
A = inv(V');
% xx = V'*x
% x = V'\xx = W'*xx
% |xx| = 1
yy = V \ (-rft+y);
SX = sum(A,1);
SXu = SX/su;
SXl = SX/sl;
% ReTurn = (1-x'*ONE)*rft+x'*y
% return = rtf - x'*(rtf + y)
% = rft + xx'*yy
% with yy = W*(-rft+y)
% maximize (xx'*yy)
% such that
% |xx| = 1
% SXu*xx <= 2
% SXl*xx <= 1
xx = yy/norm(yy);
if SXu*xx > 1
n2 = (SXu*SXu');
cs2 = 1/n2;
sn = sqrt(1-cs2);
Tu = null(SXu);
yyu = Tu*(Tu'*yy);
xx = cs2*SXu' + (sn/norm(yyu))*yyu;
elseif SXl*xx > 1
n2 = (SXl*SXl');
cs2 = 1/n2;
sn = sqrt(1-cs2);
Tl = null(SXl);
yyl = Tl*(Tl'*yy);
xx = cs2*SXl' + (sn/norm(yyl))*yyl;
end
x = V' \ xx
% Check constraints
sum(x)
x'*S*x
  5 comentarios
gsourop
gsourop el 5 de Nov. de 2018
I am getting an error on the dimensions of the matrix. Hence, I replaces this line with
Scaling = sqrt(diag(D)');
for i = 1:6
for j =1 : 6
V(i,j) = V(i,j).* Scaling(j);
end
end
but the validations at the end do not give me the expected result.
Bruno Luong
Bruno Luong el 5 de Nov. de 2018
"I am getting an error on the dimensions of the matrix"
Then apply my code wrongly. I provide the code working with some fake data
S: sym-def-pos matrix (6 x 6)
y: vector (6 x 1)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Linear Least Squares en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by