how to compile a matrix whose some elements are matrixes [message #49308] |
Fri, 14 July 2006 00:11  |
haojuanchina@gmail.co
Messages: 3 Registered: July 2006
|
Junior Member |
|
|
Hello,everyone
I want obtain a matric whose some elements are matrixes, how to compile
the program?
example: I want to abtain the following matrix
G I 0 0 0 0 0
I G I 0 0 0 0
0 I G I 0 0 0
0 0 I G I 0 0
0 0 0 I G I 0
0 0 0 0 I G I
0 0 0 0 0 I G
in which I is an identity matrix,
1 0 0 0 0 0 0
0 1 0 0 0 0 0
0 0 1 0 0 0 0
0 0 0 1 0 0 0
0 0 0 0 1 0 0
0 0 0 0 0 1 0
0 0 0 0 0 0 1
and G is a similar diagonal matrix:
1 2 0 0 0 0 0
2 1 2 0 0 0 0
0 2 1 2 0 0 0
0 0 2 1 2 0 0
0 0 0 2 1 2 0
0 0 0 0 2 1 2
0 0 0 0 0 2 1
I can compile the program of the matrix G and I:
PRO Matrix
diag =findgen(7)
sub=findgen(6)
super=findgen(6)
diag[0:6]=1
sub[0:5]=2
super[0:5]=2
G = DIAG_MATRIX(diag) + $
DIAG_MATRIX(super, 1) + DIAG_MATRIX(sub, -1)
G[0,1:5]=2
G[1:5,0]=2
print,G
I= identity(7)
print,I
END
but how to get the first matrix in which include the matrix G and I?
The difficulty is that I can not compile the diagonal elements (the
smaller matrixes) of the larger matrix. How should I do?
Thanks!
Juan Hao
|
|
|
Re: how to compile a matrix whose some elements are matrixes [message #49391 is a reply to message #49308] |
Fri, 14 July 2006 09:34  |
Jean H.
Messages: 472 Registered: July 2006
|
Senior Member |
|
|
Hello,
well, your array will hold two different things: an int and an array of int.
If you want to keep your zeroes as individual values, maybe you should
consider using a pointer. You create a 7*7 pointer array, and you assign
either the value 0 or the matrix G or I to each cell.
mat = ptrarr(7,7)
(*mat)[0,0] = G
(*mat)[0,3] = 0
If you don't mind to replicate your zeroes (in a 7,7 array), just create
a 49*49 array and fill it with G,I and the 7*7 zeroes array!
mat[0,0] = G
mat[7,0] = I
Jean
haojuanchina@gmail.com wrote:
> Hello,everyone
> I want obtain a matric whose some elements are matrixes, how to compile
>
> the program?
> example: I want to abtain the following matrix
> G I 0 0 0 0 0
> I G I 0 0 0 0
> 0 I G I 0 0 0
> 0 0 I G I 0 0
> 0 0 0 I G I 0
> 0 0 0 0 I G I
> 0 0 0 0 0 I G
> in which I is an identity matrix,
> 1 0 0 0 0 0 0
> 0 1 0 0 0 0 0
> 0 0 1 0 0 0 0
> 0 0 0 1 0 0 0
> 0 0 0 0 1 0 0
> 0 0 0 0 0 1 0
> 0 0 0 0 0 0 1
> and G is a similar diagonal matrix:
> 1 2 0 0 0 0 0
> 2 1 2 0 0 0 0
> 0 2 1 2 0 0 0
> 0 0 2 1 2 0 0
> 0 0 0 2 1 2 0
> 0 0 0 0 2 1 2
> 0 0 0 0 0 2 1
> I can compile the program of the matrix G and I:
> PRO Matrix
>
> diag =findgen(7)
> sub=findgen(6)
> super=findgen(6)
>
>
> diag[0:6]=1
> sub[0:5]=2
> super[0:5]=2
>
>
> G = DIAG_MATRIX(diag) + $
> DIAG_MATRIX(super, 1) + DIAG_MATRIX(sub, -1)
> G[0,1:5]=2
> G[1:5,0]=2
> print,G
>
> I= identity(7)
> print,I
>
> END
>
>
> but how to get the first matrix in which include the matrix G and I?
> The difficulty is that I can not compile the diagonal elements (the
> smaller matrixes) of the larger matrix. How should I do?
> Thanks!
> Juan Hao
>
|
|
|