MathGroup Archive 2006

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

Search the Archive

Re: mathematica newbie question


"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


  • Prev by Date: Re: Simplifying algebraic expressions
  • Next by Date: Re: New Analytical Functions - Mathematica Verified
  • Previous by thread: Re: mathematica newbie question
  • Next by thread: Re: mathematica newbie question