How to covert vector A to symmetric matrix M in MATLAB
Such that M is a symmetric matrix (i.e. A21=A12) and all diagonal terms are equal (i.e. A11=A22=A33=A44).
Use hankel
to help you create the symmetric matrix, then when you're finished, set the diagonal entries of this intermediate result to be the first element of the vector in A
:
M = hankel(A,A(end:-1:1));
M(eye(numel(A))==1) = A(1);
>> A = [1;2;3;4]
A =
1
2
3
4
>> M = hankel(A,A(end:-1:1));
>> M(eye(numel(A))==1) = A(1)
M =
1 2 3 4
2 1 4 3
3 4 1 2
4 3 2 1
As you can see, M(i,j) = M(j,i)
except for the diagonal, where each element is equal to A(1)
.
A
toM
. What is the general rule of construction? What happens when you extend this beyond 4 elements in the vector? – rayryengtoeplitz
. – rayryeng