Group Abstract Group Abstract

Message Boards Message Boards

How can I mirror the values of a matrix about its diagonal?

So I am generating large matrices (the smallest is 48x48) but only one half of the matrix is viable. Unltimately, what I need is a matrix that is symmetric about the diagonal. At the moment, I am just copying and pasting the values that I need, which is highly impractical as the size of the matrix scales up. The function I am using to generate the values is based off of the difference between the row and column, and so it generates different results when this value is negative verses positive. It also doesnt help to just wrap the difference in an Abs[], for whatever reason (I will post the code at the bottom just in case their is a way to get symmetry without messing with the matrices). I havent really been able to think of a way to do this, but what I would like to be able to do is just redefine all of the values on one half of the diagonal using the "correct" values on the other side of the diagonal. In this particular instance, the "correct" values are those in which m>n in the m x n matrix. 
pA[ j_, v_] := -I*(-1)^j*(2*DeA*MA)^(1/2)*K[ j, v ]

K[ j_, v_ ] := ((Gamma[ k - v - j ]*Factorial[ v + j ]*(k - 2*v - 2*j - 1)*(k - 2*v - 1))/(Gamma[ k - v ]*Factorial[ v ]))^(1/2)*(1/ k)

k := (4*DeA)/(\[HBar]*\[Omega]eA)

All of those values are then used to generate the matrix, which I have called matpA:
matpA := Table[pA[((m - 1) - (n - 1)), (n - 1)], {m, vmaxA}, {n, vmaxA}]

Thanks so much for taking the time to read this and for any help you can provide!
POSTED BY: Cole Rodman
6 months ago
If tri was a lower triangular n x n matrix, how about:
Array[If[#1 > #2, tri[[#1, #2]], tri[[#2, #1]]] &, {n, n}]
You are still copying, but maybe with less code.

If this looked cryptic, then you'd probably like to check these documentation pages:
POSTED BY: Peter Fleck
6 months ago
I used the following approach on large sparse matrix (10000 x 10000):
A =  T + Transpose[T]-Diagonal[T]
I Suppose your initial matrix is called T , the diagonal is Ok as well as the lower triangular (or the upper, does not matter), I assume you you built it limiting the calculated terms T[[m,n]] such as m<=n, the rest being initialized at zero.The resulting matrix is called A (can be T as well).
Best regards

POSTED BY: Christian Neel
6 months ago