Here is a complex problem. I have an arbitrary square matrix in R (can be in Julia as well), for example
> set.seed(420)
> A <- matrix(runif(16),nrow = 4,byrow = T)
> A
[,1] [,2] [,3] [,4]
[1,] 0.6055390 0.9702770 0.1744545 0.4757888
[2,] 0.7244812 0.8761027 0.3775037 0.6409362
[3,] 0.6546772 0.5062158 0.3033477 0.7162497
[4,] 0.2905202 0.1962252 0.3225786 0.8404279
I want to transform this matrix in a symmetric matrix, so that the off-diagonal elements are always the minimum of the 2 corresponding off-diagonal elements of the A
matrix. In the above case, the result must be:
[,1] [,2] [,3] [,4]
[1,] 0.6055390 0.7244812 0.1744545 0.2905202
[2,] 0.7244812 0.8761027 0.3775037 0.1962252
[3,] 0.1744545 0.3775037 0.3033477 0.3225786
[4,] 0.2905202 0.1962252 0.3225786 0.8404279
Would like an efficient and non-time consuming way of programming it in Julia and/or R. Must be applicable to any kind of square matrix.