Search code examples
matrixwolfram-mathematica

Average Upper and Lower Triangle Matrices


Is there an existing method in Matematica to average the corresponding elements in a lower left and upper right triangle matrix.

For example given the following matrix:

enter image description here

Which in Matematica form looks like: {{1,2.2,3},{2.1,1,4},{2.5,2,1}}

I would like to get:

enter image description here

Which in Mathematica form would be: {{1,0,0},{2.15,1,0},{2.75,3,1}}


Solution

  • I found the answer. There is not built-in function that I could find but using Transpose and addition/division operators I was able to easily come-up with a solution as follows:

    mata={{1,2.2,3},{2.1,1,4},{2.5,2,1}};
    matb=Transpose[mata];
    mata=LowerTriangularize[mata];
    matb=LowerTriangularize[matb];
    avgmat=(mata+matb)/2;
    MatrixForm[avgmat]
    

    enter image description here