[R] kronecker sum

Duncan Murdoch
Sun, 05 Jun 2011 13:41:23 -0000

On 11-06-05 9:36 AM, Lara Poplarski wrote:
> Dear All,
>
> Could someone please suggest how to find the Kronecker sum of two 2x2
> matrices,
> i.e. given two matrices:
>
> -A  A
> a  -a
>
> and
>
> -B   B
> b  -b
>
> I need:
>
>   -A-B    A       B      0
>   a     -a-B     0      B
>   b        0     -A-b  A
>   0        b       a    -a-b
>

Why not do it in the obvious way?

A <- matrix1[1,2]
a <- matrix1[2,1]
B <- matrix2[1,2]
b <- matrix2[2,1]
matrix(c(-A-B,a,b,0,  A,-a-B,0,b, B,0,-A-b,a, 0,B,A,-a-b), 4,4)

Duncan Murdoch