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.5628116  1.7219204 -0.3175465  0.0000000  0.0000000  0.00000000
#>  [2,]  0.2745670  1.3820914  0.3849507  0.0000000  0.0000000  0.00000000
#>  [3,] -2.0342097 -0.7593757 -0.9729072  0.0000000  0.0000000  0.00000000
#>  [4,]  0.1179980  0.5612935 -1.3698580  0.0000000  0.0000000  0.00000000
#>  [5,] -0.9097598  0.8852550  0.8968501  0.0000000  0.0000000  0.00000000
#>  [6,]  0.0000000  0.0000000  0.0000000 -0.6249799 -0.7176549 -0.06276950
#>  [7,]  0.0000000  0.0000000  0.0000000 -0.7797451 -2.7100979 -0.03490922
#>  [8,]  0.0000000  0.0000000  0.0000000  1.2796313  2.7958443 -0.21687812
#>  [9,]  0.0000000  0.0000000  0.0000000 -1.4297238  0.3794059 -0.22914234
#> [10,]  0.0000000  0.0000000  0.0000000  0.3970476 -0.4381274 -1.66090998
#> [11,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.00000000
#> [12,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.00000000
#>             [,7]        [,8]       [,9]      [,10]      [,11]     [,12]
#>  [1,]  0.0000000  0.00000000  0.0000000  0.0000000  0.0000000 0.0000000
#>  [2,]  0.0000000  0.00000000  0.0000000  0.0000000  0.0000000 0.0000000
#>  [3,]  0.0000000  0.00000000  0.0000000  0.0000000  0.0000000 0.0000000
#>  [4,]  0.0000000  0.00000000  0.0000000  0.0000000  0.0000000 0.0000000
#>  [5,]  0.0000000  0.00000000  0.0000000  0.0000000  0.0000000 0.0000000
#>  [6,] -0.7761330  0.44852873  0.3410861  0.0000000  0.0000000 0.0000000
#>  [7,] -0.4206652  0.09251393 -1.7769656  0.0000000  0.0000000 0.0000000
#>  [8,]  0.2000292 -2.40971504 -0.2927353  0.0000000  0.0000000 0.0000000
#>  [9,] -0.1569063 -0.08627375  1.1934303  0.0000000  0.0000000 0.0000000
#> [10,] -0.3269648 -0.21747444 -0.5855999  0.0000000  0.0000000 0.0000000
#> [11,]  0.0000000  0.00000000  0.0000000  0.8196505 -0.3833653 0.5830504
#> [12,]  0.0000000  0.00000000  0.0000000 -0.7411759  0.4562687 0.5749869
#>            [,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.9218250 -1.5184143  1.3043819 -0.1669161 -0.3930158 -0.5676033
#> [12,] -0.1719824  0.1819156 -0.6362032  0.9164283  2.0092496 -1.3728255