Re: mathematica newbie question
- To: mathgroup at smc.vnet.net
- Subject: [mg66897] Re: mathematica newbie question
- From: "David W.Cantrell" <DWCantrell at sigmaxi.org>
- Date: Sat, 3 Jun 2006 03:25:17 -0400 (EDT)
- References: <e5osv8$i51$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
"Jeremy Watts" <jwatts1970 at hotmail.com> wrote:
> Hi,
>
> Just trying to get to grips with Mathematica and matrices. Why is it
> when I enter :-
> {0, 0, 0}, {1, -1, -1}, {-1, 1, 1}}^2
>
> then Mathematica returns :-
>
> {{0, 0, 0}, {1, 1, 1}, {1, 1, 1}}
>
> and not {{0,0,0},{0,0,0},{0,0,0}} (the actual square of the matrix) as
> I'd have expected?
>
> Is it treating what I entered as separate vectors or something, and not
> an actual matrix?
Something like that.
In[9]:= matr={{0, 0, 0}, {1, -1, -1}, {-1, 1, 1}}
Out[9]= {{0,0,0},{1,-1,-1},{-1,1,1}}
In[10]:= matr^2
Out[10]= {{0,0,0},{1,1,1},{1,1,1}}
In the above, it merely squared every element (inside the inner lists).
In[11]:= matr matr
Out[11]= {{0,0,0},{1,1,1},{1,1,1}}
Here, it multiplied elementwise, so to speak. The result was the same as
Out[10] since we were multiplying matr with itself. But of course, these
were not what you wanted. You need to specify a specialized matrix
operation, rather than expecting Mathematica to recognize somehow that that
is what you want. Here are two ways:
In[12]:= matr . matr
Out[12]= {{0,0,0},{0,0,0},{0,0,0}}
In[13]:= MatrixPower[matr,2]
Out[13]= {{0,0,0},{0,0,0},{0,0,0}}
David Cantrell