MATLAB Answers

Creating Matrix provided elements

조회 수: 2(최근 30일)
Karthik Nagaraj
Karthik Nagaraj 2021년 7월 22일
댓글: Karthik Nagaraj 2021년 7월 24일
From a Hermititan (complex skew symmetric) matrix of order N (Asssume N=15) a column vector is created such that all the diagonal elements are placed first and then the ordered pair of real and imaginary parts of upper triangle matrix are placed next. Since it is hermitian matrix the upper and lower triangle elements have same set of real and imaginary elements.
For example for N=15x15 matrix the vector looks like this
[D1, D2, D3,...........,D15, R11, I11,R12, I12,.... ,R15, I15] in total 225 elements column vector.
How to construct back the matrix given this vector?
  댓글 수: 4
Karthik Nagaraj
Karthik Nagaraj 2021년 7월 23일
Hermitian Matrix N=4. Always Diagonal are real. Upper triangle elements are complex conjuagte of Lower triangle elements
disp(H)
0.9490 + 0.0000i -0.0222 + 0.8156i -1.2365 + 0.4256i -0.1310 - 0.4833i
-0.0222 - 0.8156i 0.3080 + 0.0000i -0.0918 + 1.2658i -0.3776 - 0.1952i
-1.2365 - 0.4256i -0.0918 - 1.2658i -0.9261 + 0.0000i -0.0571 - 0.9267i
-0.1310 + 0.4833i -0.3776 + 0.1952i -0.0571 + 0.9267i 0.2858 + 0.0000i
I have created a funciton that can extract Diagonal elements, Upper triangle elements in ordered pair (R-Real and I-Imaginary element one after the other and form a vector of these.
Diagonal elements
disp(D)
0.9490
0.3080
-0.9261
0.2858
Upper triangle elements ordered pair. Real and imaginary pair next to each other
disp(UOP)
-0.0222 0.8156 -1.2365 0.4256 -0.0918 1.2658 -0.1310 -0.4833 -0.3776 -0.1952 -0.0571 -0.9267
The final concatenated vector VU.
Columns 1 through 13
0.9490 0.3080 -0.9261 0.2858 -0.0222 0.8156 -1.2365 0.4256 -0.0918 1.2658 -0.1310 -0.4833 -0.3776
Columns 14 through 16
-0.1952 -0.0571 -0.9267
I have more than 1000 vectors like 'VU'. I need to reconstruct the oroginal matrix H with vector VU given.
Some similar Matlab forum solution is given in
But could not improvise further

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

채택된 답변

Jan
Jan 2021년 7월 24일
편집: Jan 2021년 7월 24일
A = rand(4) + 1i * rand(4);
A = A + A'; % Hermitian
% Convert to vector:
D = diag(A).';
L = triu(A, 1);
Lf = L(L ~= 0).';
Lv = [real(Lf); imag(Lf)];
VU = [D, Lv(:).'];
% And backwards:
n = sqrt(numel(VU));
L = triu(ones(n), 1);
L(L==1) = VU(n+1:2:n*n) + 1i * VU(n+2:2:n*n);
% Or: L(L==1) = [1, 1i] * reshape(VU(n+1:n*n), 2, [])
B = diag(VU(1:n)) + L + L';
isequal(A, B)
ans = logical
1
  댓글 수: 1
Karthik Nagaraj
Karthik Nagaraj 2021년 7월 24일
The first part of converting matrix to vector looks exactly as my function. But the code for reconstruction of the matrix back from the vector is really good. This must be one of the best answers! Thank you!

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

추가 답변(0개)

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by