[R] kronecker sum
(Ted Harding)
ted.harding at wlandres.net
Sun Jun 5 16:37:36 CEST 2011
On 05-Jun-11 13:36:18, 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
>
> Many thanks,
> Lara
For example, let A=10, a=2, B=5, b=3 so that your
-A-B A B 0
a -a-B 0 B
b 0 -A-b A
0 b a -a-b
is
-15 10 5 0
2 -7 0 5
3 0 -13 10
0 3 2 -5
Then, in R,
M <- matrix(c(-10,10,2,-2),byrow=TRUE,ncol=2)
N <- matrix(c(-5,5,3,-3),byrow=TRUE,ncol=2)
I <- diag(1,2,2)
kronecker(I,M) + kronecker(N,I)
# [,1] [,2] [,3] [,4]
# [1,] -15 10 5 0
# [2,] 2 -7 0 5
# [3,] 3 0 -13 10
# [4,] 0 3 2 -5
See '?kronecker'.
Hoping this helps.
Ted.
--------------------------------------------------------------------
E-Mail: (Ted Harding) <ted.harding at wlandres.net>
Fax-to-email: +44 (0)870 094 0861
Date: 05-Jun-11 Time: 15:37:32
------------------------------ XFMail ------------------------------
More information about the R-help
mailing list