1
votes

How to covert vector A to symmetric matrix M in MATLAB

enter image description here

enter image description here

Such that M is a symmetric matrix (i.e. A21=A12) and all diagonal terms are equal (i.e. A11=A22=A33=A44).

1
We don't support LaTeX here. Please use coding syntax. In addition, I can't see how to go from A to M. What is the general rule of construction? What happens when you extend this beyond 4 elements in the vector?rayryeng
Please see the revised questionASE
That's better. Thanks. I'm reopening as this isn't a duplicate of using toeplitz.rayryeng
where is the A31, A13 element? or A24, A42?percusse

1 Answers

1
votes

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);

Example

>> 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).