Re: a matrix whose some elements are matrixes [message #49281] |
Mon, 10 July 2006 02:12 |
Paolo Grigis
Messages: 171 Registered: December 2003
|
Senior Member |
|
|
Here's a small example which should help you:
a=[[1,0],[0,1]]
b=[[2,2],[2,2]]
IDL> print,a
1 0
0 1
IDL> print,b
2 2
2 2
To have a matrix c=[[a,b],[b,a]] do:
c=intarr(4,4)
c[0,0]=a
c[0,2]=b
c[2,0]=b
c[2,2]=a
The output is:
IDL> print,c
1 0 2 2
0 1 2 2
2 2 1 0
2 2 0 1
The trick is to figure out where the upper left corners of the smaller matrices
fit into the larger matrix you want to build...
Ciao,
Paolo
haojuanchina@gmail.com wrote:
> I want obtain a matric whose some elements are matrixes, how to compile
> the program?
> example: Iwant to abtain the following matrix
> G I I I I I 0
> I G I 0 0 0 0
> I I G I 0 0 0
> I 0 I G I 0 0
> I 0 0 I G I 0
> I 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 -0.25 -0.25 -0.25 -0.25 -0.25 0
> -0.25 1 0 0 0 0 0
> -0.25 0 1 0 0 0 0
> -0.25 0 0 1 0 0 0
> -0.25 0 0 0 1 0 0
> -0.25 0 0 0 0 1 0
> 0 0 0 0 0 0 1
> I can compile the program of the matrix G:
> PRO Matrix
>
> diag =findgen(7)
> sub=findgen(6)
> super=findgen(6)
>
> diag[0:6]=1
> sub[0:5]=-0.25
> super[0:5]=-0.25
>
> G = DIAG_MATRIX(diag) + $
> DIAG_MATRIX(super, 1) + DIAG_MATRIX(sub, -1)
> G[0,1:5]=-0.25
> G[1:5,0]=-0.25
> print,G
>
> I= DIAG_MATRIX(diag[0:6]);*(-0.25)
> print,I
>
> END
>
> but how to get the first matrix in which include the matrix G and I ?
> Please give me a help!thanks.
>
|
|
|