Computes the direct sum of all matrices passed in via the list.

direct_sum(x)

Arguments

x

A field<matrix> or list containing matrices

Value

Matrix containing the direct sum of all matrices in the list.

Details

Consider matrix \(A\) (\(M \times N\)) and \(B\) (\(K \times P\)). A direct sum is a diagonal matrix \(A (+) B\) with dimensions \((m + k) x (n + p)\).

Author

James Joseph Balamuta

Examples


x = list(matrix(0, nrow = 5, ncol = 3),
         matrix(1, nrow = 5, ncol = 3))
direct_sum(x)
#>       [,1] [,2] [,3] [,4] [,5] [,6]
#>  [1,]    0    0    0    0    0    0
#>  [2,]    0    0    0    0    0    0
#>  [3,]    0    0    0    0    0    0
#>  [4,]    0    0    0    0    0    0
#>  [5,]    0    0    0    0    0    0
#>  [6,]    0    0    0    1    1    1
#>  [7,]    0    0    0    1    1    1
#>  [8,]    0    0    0    1    1    1
#>  [9,]    0    0    0    1    1    1
#> [10,]    0    0    0    1    1    1

x = list(matrix(rnorm(15), nrow = 5, ncol = 3),
         matrix(rnorm(30), nrow = 5, ncol = 6),
         matrix(rnorm(18), nrow = 2, ncol = 9))
direct_sum(x)
#>            [,1]         [,2]       [,3]         [,4]       [,5]       [,6]
#>  [1,] 0.8679492 -0.079081199  2.0359604  0.000000000  0.0000000  0.0000000
#>  [2,] 0.4738486  1.931351096 -0.9596798  0.000000000  0.0000000  0.0000000
#>  [3,] 0.4878884  2.120571320 -0.6044085  0.000000000  0.0000000  0.0000000
#>  [4,] 1.8528172  0.003966124 -0.2421029  0.000000000  0.0000000  0.0000000
#>  [5,] 0.5814289  0.965862275  1.2115386  0.000000000  0.0000000  0.0000000
#>  [6,] 0.0000000  0.000000000  0.0000000  1.578944645 -1.7151922 -1.0106199
#>  [7,] 0.0000000  0.000000000  0.0000000  0.440601529 -0.2396853  0.5514397
#>  [8,] 0.0000000  0.000000000  0.0000000  1.781942012 -0.2209881 -0.1385003
#>  [9,] 0.0000000  0.000000000  0.0000000  0.504170155 -0.9121694 -1.0621207
#> [10,] 0.0000000  0.000000000  0.0000000 -0.006280381 -1.5767439 -1.1798228
#> [11,] 0.0000000  0.000000000  0.0000000  0.000000000  0.0000000  0.0000000
#> [12,] 0.0000000  0.000000000  0.0000000  0.000000000  0.0000000  0.0000000
#>             [,7]       [,8]       [,9]      [,10]      [,11]      [,12]
#>  [1,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [2,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [3,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [4,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [5,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [6,] -1.0138381 -0.2800320 -2.8901024  0.0000000  0.0000000  0.0000000
#>  [7,] -0.3489747  2.2259691 -0.2767730  0.0000000  0.0000000  0.0000000
#>  [8,]  0.8411251 -1.7624051 -0.1669105  0.0000000  0.0000000  0.0000000
#>  [9,] -1.2904265 -0.7177486  1.3225655  0.0000000  0.0000000  0.0000000
#> [10,] -0.2503535 -0.3741344  1.7872447  0.0000000  0.0000000  0.0000000
#> [11,]  0.0000000  0.0000000  0.0000000 -0.4072574  1.9481586  0.3655616
#> [12,]  0.0000000  0.0000000  0.0000000 -0.7192638 -0.9286569 -0.1275307
#>            [,13]      [,14]     [,15]     [,16]      [,17]      [,18]
#>  [1,]  0.0000000  0.0000000 0.0000000 0.0000000  0.0000000  0.0000000
#>  [2,]  0.0000000  0.0000000 0.0000000 0.0000000  0.0000000  0.0000000
#>  [3,]  0.0000000  0.0000000 0.0000000 0.0000000  0.0000000  0.0000000
#>  [4,]  0.0000000  0.0000000 0.0000000 0.0000000  0.0000000  0.0000000
#>  [5,]  0.0000000  0.0000000 0.0000000 0.0000000  0.0000000  0.0000000
#>  [6,]  0.0000000  0.0000000 0.0000000 0.0000000  0.0000000  0.0000000
#>  [7,]  0.0000000  0.0000000 0.0000000 0.0000000  0.0000000  0.0000000
#>  [8,]  0.0000000  0.0000000 0.0000000 0.0000000  0.0000000  0.0000000
#>  [9,]  0.0000000  0.0000000 0.0000000 0.0000000  0.0000000  0.0000000
#> [10,]  0.0000000  0.0000000 0.0000000 0.0000000  0.0000000  0.0000000
#> [11,]  0.4920717 -0.1978193 1.0157872 0.3581453  1.2529534 -1.2678879
#> [12,] -1.0691865  0.7393204 0.2089057 0.1224596 -0.6101309  0.8349744