MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Matrix Problem


nilaakash wrote:
> Hi,
>        I face a problem to get (3xn) matrix data.  Here I am giving a
> simple example.
>
>         data = Table[{Sin[x], Cos[y], Sin[x] Cos[y]}, {x, 0, 3, 1},
> {y, 0, 2, 1}];
>         MatrixForm[data]
>
>  It prints a (4x3) block matrix.
>
> Could anybody tell me how shall I get only 3 column matrix like
> following matrix ?
>
>         Sin[0]          Cos[0]             Sin[0] Cos[0]
>         Sin[1]          Cos[0]             Sin[1] Cos[0]
>         Sin[2]          Cos[0]             Sin[2] Cos[0]
>         Sin[3]          Cos[0]             Sin[3] Cos[0]
>         Sin[0]          Cos[1]             Sin[0] Cos[1]
>         Sin[1]          Cos[1]             Sin[1] Cos[1]
>         Sin[2]          Cos[1]             Sin[2] Cos[1]
>         Sin[3]          Cos[1]             Sin[3] Cos[1]
>         Sin[0]          Cos[2]             Sin[0] Cos[2]
>         Sin[1]          Cos[2]             Sin[1] Cos[2]
>         Sin[2]          Cos[2]             Sin[2] Cos[2]
>         Sin[3]          Cos[2]             Sin[3] Cos[2]
>
> Thanks.
>
> Nilaakash

To get the terms in the order you listed them,
swap the x and y loops in the Table commmand.

To convert the 3 x 4 x 3 table to a 12 x 3 matrix, Flatten it once.

data = Table[{Sin[x],Cos[y],Sin[x]*Cos[y]},{y,0,2},{x,0,3}];
TableForm@Flatten[data,1]


0        1        0
Sin[1]   1        Sin[1]
Sin[2]   1        Sin[2]
Sin[3]   1        Sin[3]
0        Cos[1]   0
Sin[1]   Cos[1]   Cos[1] Sin[1]
Sin[2]   Cos[1]   Cos[1] Sin[2]
Sin[3]   Cos[1]   Cos[1] Sin[3]
0        Cos[2]   0
Sin[1]   Cos[2]   Cos[2] Sin[1]
Sin[2]   Cos[2]   Cos[2] Sin[2]
Sin[3]   Cos[2]   Cos[2] Sin[3]


  • Prev by Date: Re: Problems with ExtendGraphics/Delaunay Triangulation
  • Next by Date: Re: random matrix from row and column sums
  • Previous by thread: Re: Matrix Problem
  • Next by thread: Problems with ExtendGraphics/Delaunay Triangulation