MathGroup Archive 2007

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

Search the Archive

Re: 2X2 arrays

  • To: mathgroup at smc.vnet.net
  • Subject: [mg74671] Re: 2X2 arrays
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Fri, 30 Mar 2007 03:03:05 -0500 (EST)
  • Organization: The Open University, Milton Keynes, UK
  • References: <eufpvj$7ee$1@smc.vnet.net>

simad at cse.iitkgp.ernet.in wrote:
> Hi,
> 
> I am wondering how to initialize a set of 2X2 arrays in an array.
> for example: 
> a1=1/Sqrt[2]{{1,1},{1,-1}}
> a2=1/Sqrt[2]{{1,0},{0,1}}
> a3=1/Sqrt[2]{{1+I,0},{0,1-I}}
> a4=1/Sqrt[2]{{1,1-I},{1,1+I}}
[snip]

I am not sure to have fully understood your request, but you can create 
an array of 2 by 2 arrays as a list of lists of lists (in Mathematica 
speak). For instance,

In[1]:=
a1 = (1/Sqrt[2])*{{1, 1}, {1, -1}};
a2 = (1/Sqrt[2])*{{1, 0}, {0, 1}};
a3 = (1/Sqrt[2])*{{1 + I, 0}, {0, 1 - I}};
a4 = (1/Sqrt[2])*{{1, 1 - I}, {1, 1 + I}};
a = {a1, a2, a3, a4}

Out[5]=
       1        1          1          1
{{{-------, -------}, {-------, -(-------)}},
    Sqrt[2]  Sqrt[2]    Sqrt[2]    Sqrt[2]

        1                1
   {{-------, 0}, {0, -------}},
     Sqrt[2]          Sqrt[2]

      1 + I            1 - I
   {{-------, 0}, {0, -------}},
     Sqrt[2]          Sqrt[2]

        1      1 - I        1      1 + I
   {{-------, -------}, {-------, -------}}}
     Sqrt[2]  Sqrt[2]    Sqrt[2]  Sqrt[2]

In[6]:=
Dimensions[a]

Out[6]=
{4, 2, 2}

Or you can create the array of arrays directly as in,

In[7]:=
array = (1/Sqrt[2])*{{{1, 1}, {1, -1}}, {{1, 0}, {0, 1}},
     {{1 + I, 0}, {0, 1 - I}}, {{1, 1 - I}, {1, 1 + I}}}

Out[7]=
       1        1          1          1
{{{-------, -------}, {-------, -(-------)}},
    Sqrt[2]  Sqrt[2]    Sqrt[2]    Sqrt[2]

        1                1
   {{-------, 0}, {0, -------}},
     Sqrt[2]          Sqrt[2]

      1 + I            1 - I
   {{-------, 0}, {0, -------}},
     Sqrt[2]          Sqrt[2]

        1      1 - I        1      1 + I
   {{-------, -------}, {-------, -------}}}
     Sqrt[2]  Sqrt[2]    Sqrt[2]  Sqrt[2]

In[8]:=
a === array

Out[8]=
True

Regards,
Jean-Marc



  • Prev by Date: Re: comments in import files
  • Next by Date: Re: Definite Integration in Mathematica
  • Previous by thread: Re: 2X2 arrays
  • Next by thread: ReadList