Vector to lower-triangular matrix

조회 수: 11 (최근 30일)
Somebody
Somebody 2013년 3월 5일
편집: Matt J 2021년 6월 29일
Hello.
Im trying to estimate multivariate normal distribution. Correlation matrix is one of the parameters, and I need to have all parameters in a vector for fmincon.
I can vectorize a lower-triangular of correlation matrix, indeed, but how do I do an opposite?
I mean, I have a matrix C - a correlation matrix:
1 c12 c13
C = c12 1 c23
c13 c23 1
Then I do:
a = tril(C,-1);
a = a(:);
b = a(a(:)>0);
b = [c12; c13; c23];
I get b - a vectorized lower-triangular matrix. How can I do an opposite (for matrices of any dimensions)? To get a lower-triangular matrix from a vector? Thanks!

답변 (1개)

Matt J
Matt J 2021년 6월 29일
편집: Matt J 2021년 6월 29일
b=rand(1,10)
b = 1×10
0.5909 0.3646 0.0131 0.7843 0.1867 0.2957 0.2750 0.2019 0.1148 0.6168
n=roots([1,1,-2*numel(b)]);
n=n(n>0)+1;
validateattributes(n,{'numeric'},{'positive', 'integer'}) %numel(b) must be a pyramidal number
C=tril(ones(n),-1);
C(logical(C))=b;
C=C+C.'+eye(n)
C = 5×5
1.0000 0.5909 0.3646 0.0131 0.7843 0.5909 1.0000 0.1867 0.2957 0.2750 0.3646 0.1867 1.0000 0.2019 0.1148 0.0131 0.2957 0.2019 1.0000 0.6168 0.7843 0.2750 0.1148 0.6168 1.0000

카테고리

Help CenterFile Exchange에서 Multivariate Distributions에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by