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

2 ビュー (過去 30 日間)
gsourop
gsourop 2018 年 10 月 29 日
コメント済み: Bruno Luong 2018 年 11 月 5 日
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 件のコメント
Bruno Luong
Bruno Luong 2018 年 10 月 30 日
Yes, even the sqrt() might return complex result.
gsourop
gsourop 2018 年 10 月 30 日
I see. But is there a way to impose the additional constraints without solving the relationship arithmetically?

サインインしてコメントする。

採用された回答

Bruno Luong
Bruno Luong 2018 年 10 月 30 日
編集済み: Bruno Luong 2018 年 10 月 30 日
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 件のコメント
gsourop
gsourop 2018 年 11 月 5 日
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 2018 年 11 月 5 日
"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)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLinear Least Squares についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by