lower triangular semidefinite matrix

조회 수: 2 (최근 30일)
Albert Stirling
Albert Stirling 2020년 5월 4일
댓글: Albert Stirling 2020년 5월 4일
how can i build a sparse matrix in this form for a given semidefinite matrix? i only need the sparse lower triangular of semidefinite matrix
for example a semidefinite matrix as Q0:
2 0 -1
Q0 = 0 0.2 0
-1 0 2
is written as:
i = [1 2 3 3 ];
j = [1 2 3 1 ];
c = [2 0.2 2 -1 ];
where i shows number of row
j shows number of column
and c is the elemnt that belong to (i,j) that is not zero and belong to lower triangular of semidefinite matrix
  댓글 수: 2
Guillaume
Guillaume 2020년 5월 4일
I'm not sure I understand the problem, sparse(i, j, c) would create your sparse matrix.
Guillaume
Guillaume 2020년 5월 4일
Albert Stirling's comment mistakenly posted as an Answer moved here:
I need a simple algorithm that select the non-zero values in shown lower triangular part of this symmetric matrix and return it as below:
i = [1 2 3 3 ];
j = [1 2 3 1 ];
c = [2 0.2 2 -1 ];
i need the algorithm to be flexible so i can give it any desired symmetric matrix and have an answer like the one mentioned.

댓글을 달려면 로그인하십시오.

채택된 답변

Guillaume
Guillaume 2020년 5월 4일
[i, j, c] = find(tril(yourmatrix))
seems to be what you're after.
  댓글 수: 1
Albert Stirling
Albert Stirling 2020년 5월 4일
thank you so much that was a quick way to handle this problam.
however i found a long one myself as below:
Q0=[-2 0 0.2;
0 -2 0;
0.2 0 -0.2]
[, c]=size(Q0);
for i=1:c
for j=1:3-i
Q0(i,i+j)=0;
end
end
Q1=sparse(Q0);
[i,j,s] = find(Q1);
f=[i,j,s]'

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

John D'Errico
John D'Errico 2020년 5월 4일
편집: John D'Errico 2020년 5월 4일
You just want the lower triangle elements. semi-definite-ness is irrelevant to what you asked for at the end.
A = sprand(5,5,.3);
>> full(A)
ans =
0.46421 0.83266 0 0.022104 0.18026
0.26627 0 0 0 0
0 0 0 0 0
0 0 0 0.92865 0
0 0 0.37763 0.42783 0
>> [Rind,Cind,val] = find(tril(A))
Rind =
1
2
5
4
5
Cind =
1
1
3
4
4
val =
0.46421
0.26627
0.37763
0.92865
0.42783
That is how you would EXTRACT the lower triangle into a set of row and column indices, and the non-zero elements in those positions. Which on the face of it, seems to be your question. However, my guess is that you really want to build the sparse matrix from those values? Or, perhaps you just don't understand that sparse matrices already exist in MATLAB and can be used as such? It is not at all clear what is the real problem.
Regardless, if you wanted to build the matrix as a sparse one, then just call sparse using those vectors.
Atril = sparse(Rind,Cind,val,5,5)
Atril =
(1,1) 0.46421
(2,1) 0.26627
(5,3) 0.37763
(4,4) 0.92865
(5,4) 0.42783
>> full(Atril)
ans =
0.46421 0 0 0 0
0.26627 0 0 0 0
0 0 0 0 0
0 0 0 0.92865 0
0 0 0.37763 0.42783 0
  댓글 수: 1
Albert Stirling
Albert Stirling 2020년 5월 4일
thank you, your solution seems to be a good way to solve this problam. thank you again.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Sparse Matrices에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by