1

I wonder whether there is a way how to transform symmetric matrix to diagonal matrix using symetretric transformation. I could not find any function that performs symmetric transformation in Mathematica.

E.g. I have matrix {{1,a},{a,2}} and I want to do TransformToDiagonal[{{1,a},{a,2}}]. The result should be {{1,0},{0,2-a^2}}.


Definitions: Symmetric transformation is a finite sequence of elementary symmetric operations. By elementary symmetric operation we mean applying elementary row operation and then the corresponding column operation.

velblúd
  • 113
  • 5
  • 1
    How did you get the this result{{1,0},{0,2-a^2}}? – L.K. Feb 13 '17 at 13:24
  • I added (-a)1st row to 2nd row and then (-a)1st column to 2nd column. – velblúd Feb 13 '17 at 13:25
  • Are you talking about row reduced echelon? – L.K. Feb 13 '17 at 13:26
  • Kind of, but I need to use symmetric transformation. At the end, I should have zeros everywhere except for the diagonal. – velblúd Feb 13 '17 at 13:32
  • You said I added (-a)1st row to 2nd row and then (-a)1st column to 2nd column. But how can you get this {{1,0},{0,2-a^2}} as a result? – L.K. Feb 13 '17 at 13:37
  • I have {{1,0},{a,2}}. I add -a1st row to 2nd row so I have {{1,a},{a-a=0,2-a^2}} . Then I add -a1st row to column to 2nd column so I get {{1,0},{0,2-a^2}}. I am sorry if it is not clear, I dont learn mathematics in English. – velblúd Feb 13 '17 at 13:43
  • 3
    You wrote wrong matrix in question? – L.K. Feb 13 '17 at 13:53
  • The matrix in question is right {{1,a},{a,2}}. I wrote wrong matrix in the comment... – velblúd Feb 13 '17 at 13:59
  • What exactly to you mean by "symmetric transformation"? There are infinitely many transformations which map a symmetric matrix to a diagonal matrix. – anderstood Feb 14 '17 at 14:38
  • @anderstood Symmetric transformation is a finite sequence of elementary symmetric operations. By elementary symmetric operation we mean applying elementary row operation and then the corresponding column operation. – velblúd Feb 17 '17 at 13:59

3 Answers3

4

First we need to check whether the matrix in question is symmetric or not.

SymmetricMatrixQ[{{1, a}, {a, 2}}]

True

Now we will go for row reduction to see what we get,

RowReduce[{{1, a}, {a, 2}}] // MatrixForm

\begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix}

This is not what you want. Now I will try Nassers approach to use LUDecomposition

{lu, p, c} = LUDecomposition[{{1, a}, {a, 2}}]
(u = lu SparseArray[{i_, j_} /; j >= i -> 1, {2, 2}]) // MatrixForm

\begin{pmatrix} 1 & a \\ 0 & 2-a^2 \end{pmatrix}

I maybe wrong but it seems what you are after is impossible for me to produce.

Edit

Following @george2079 suggestions, we can get the OPs desired result,

Transpose[u];
{lu, p, c} = LUDecomposition[%];
(u = lu SparseArray[{i_, j_} /; j >= i -> 1, {2, 2}]) // MatrixForm

\begin{pmatrix} 1 & 0 \\ 0 & 2-a^2 \end{pmatrix}

zhk
  • 11,939
  • 1
  • 22
  • 38
  • This seems to be working well-enough for 2x2 matrices (probably because in this case the "column" part of a symmetric transformation does not change the diagonal) , but gives completely wrong results for bigger ones. Anyway thanks for your answer. – velblúd Feb 13 '17 at 14:05
  • 1
    Transpose and repeat the LUDecomposition approach.. gives the same result as my answer. – george2079 Feb 13 '17 at 15:36
  • @george2079 Wow!. Thanks – zhk Feb 13 '17 at 15:51
  • @velblúd You should accept george2079 response as an answer not mine. I adopted his idea. – zhk Feb 13 '17 at 18:04
  • Thank you guys. I accepted this answer as it is nicer and more robust that the procedural approach. – velblúd Feb 13 '17 at 18:06
2

kind of ugly procedural approach:

n = 3
m = Table[ a[Min[i, j], Max[i, j] ], {i, n}, {j, n}] ;
Do[ m[[row]] = m[[row]] - m[[prow]]  m[[row, prow]]/m[[prow, prow]]
   , {prow, 1, n - 1} , {row, {prow + 1, n} }];
m = Transpose[m];
Do[ m[[row]] = m[[row]] - m[[prow]]  m[[row, prow]]/m[[prow, prow]]
   , {prow, 1, n - 1} , {row, {prow + 1, n} }];

m // MatrixForm

enter image description here

of course for m={{1, a}, {a, 2}} this yields {{1, 0}, {0, 2 - a^2}}

george2079
  • 38,913
  • 1
  • 43
  • 110
  • Thank you, this is what I need! Just one note - it fails if there is zero on the diagonal. (e.g. {{0,1},{0,1}}). But this is good enough for me. – velblúd Feb 13 '17 at 18:01
1

another approach

m = {{1, a}, {a, 2}};
Nest[(Transpose@UpperTriangularize@First@LUDecomposition@#) &, m, 2]
{{1, 0}, {0, 2 - a^2}}

With @george2079 matrix:

n = 3
m = Table[a[Min[i, j], Max[i, j]], {i, n}, {j, n}];
Nest[(Transpose@UpperTriangularize@First@LUDecomposition@#) &, m, 
  2] // MatrixForm

enter image description here