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.9097598  0.8852550  0.8968501  0.0000000  0.00000000  0.0000000
#>  [2,]  1.7219204 -0.3175465 -0.6249799  0.0000000  0.00000000  0.0000000
#>  [3,]  1.3820914  0.3849507 -0.7797451  0.0000000  0.00000000  0.0000000
#>  [4,] -0.7593757 -0.9729072  1.2796313  0.0000000  0.00000000  0.0000000
#>  [5,]  0.5612935 -1.3698580 -1.4297238  0.0000000  0.00000000  0.0000000
#>  [6,]  0.0000000  0.0000000  0.0000000  0.3970476 -0.43812741 -1.6609100
#>  [7,]  0.0000000  0.0000000  0.0000000 -0.7176549 -0.06276950 -0.7761330
#>  [8,]  0.0000000  0.0000000  0.0000000 -2.7100979 -0.03490922 -0.4206652
#>  [9,]  0.0000000  0.0000000  0.0000000  2.7958443 -0.21687812  0.2000292
#> [10,]  0.0000000  0.0000000  0.0000000  0.3794059 -0.22914234 -0.1569063
#> [11,]  0.0000000  0.0000000  0.0000000  0.0000000  0.00000000  0.0000000
#> [12,]  0.0000000  0.0000000  0.0000000  0.0000000  0.00000000  0.0000000
#>              [,7]       [,8]       [,9]     [,10]      [,11]      [,12]
#>  [1,]  0.00000000  0.0000000  0.0000000 0.0000000  0.0000000  0.0000000
#>  [2,]  0.00000000  0.0000000  0.0000000 0.0000000  0.0000000  0.0000000
#>  [3,]  0.00000000  0.0000000  0.0000000 0.0000000  0.0000000  0.0000000
#>  [4,]  0.00000000  0.0000000  0.0000000 0.0000000  0.0000000  0.0000000
#>  [5,]  0.00000000  0.0000000  0.0000000 0.0000000  0.0000000  0.0000000
#>  [6,] -0.32696476 -0.2174744 -0.5855999 0.0000000  0.0000000  0.0000000
#>  [7,]  0.44852873  0.3410861  0.8196505 0.0000000  0.0000000  0.0000000
#>  [8,]  0.09251393 -1.7769656 -0.7411759 0.0000000  0.0000000  0.0000000
#>  [9,] -2.40971504 -0.2927353 -0.3833653 0.0000000  0.0000000  0.0000000
#> [10,] -0.08627375  1.1934303  0.4562687 0.0000000  0.0000000  0.0000000
#> [11,]  0.00000000  0.0000000  0.0000000 0.5830504 -0.9218250 -1.5184143
#> [12,]  0.00000000  0.0000000  0.0000000 0.5749869 -0.1719824  0.1819156
#>            [,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,]  1.3043819 -0.1669161 -0.3930158 -0.5676033 1.8289455 -0.8267193
#> [12,] -0.6362032  0.9164283  2.0092496 -1.3728255 0.5753637 -0.8342814