Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1999
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1999

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

Search the Archive

RE: Automatic Display in MatrixForm

  • To: mathgroup at smc.vnet.net
  • Subject: [mg19234] RE: [mg19206] Automatic Display in MatrixForm
  • From: "Ersek, Ted R" <ErsekTR at navair.navy.mil>
  • Date: Wed, 11 Aug 1999 02:06:48 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

Bruno Daniel  wrote:
----------------------
I found a way to display matrices automatically in MatrixForm
without having to place the annoying   "// MatrixForm" in the end
of each line. Just put the following line into your init.m:

$Post=(#/.x_?MatrixQ->MatrixForm[x])&

This also works for output that doesn't *consist* of a matrix, but 
*contains* matrices.
----------------------------

That's nice, but it sometimes spells disaster.


In[1]:=
$Post=(#/.x_?MatrixQ->MatrixForm[x])&;

In[2]:=
x=3+y;

In[3]:=
mtrx={{2,0,0},{0,-1,0},{0,0,3}}

Out[3]//MatrixForm=
3+y


What *%&^  !!
-----------------

You used (lhs->rhs) in $Post, and Rule uses the global value of (x) in
(rhs).  Hence the result in Out[3] is very wrong!  However, (mtrx) actually
has the right value.  Below the first row of (mtrx) is displayed.


In[4]:=
First[mtrx]

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

-----------------------------
What you need to do is use (lhs:>rhs) as below.

In[5]:=
$Post=(#/.x_?MatrixQ:>MatrixForm[x])&;

In[6]:=
mtrx

Out[6]//MatrixForm=
(* The desired output is displayed. *)

----------------------------

It's no wonder people keep making this mistake in spite of me pointing it
out over and over.  The Mathematica Book (all editions) are full of examples
that will give the same type of error when the variable used has a global
value.  The book does nothing to warn users about this problem, or how to
avoid it.  Has Stephen Wolfram not been aware of this for the past 10 years,
or does he think it's in his best interest to avoid bringing it to our
attention?

As far as I can tell WRI tech support doesn't have a web page addressing
this problem.

Besides that there are dozens of books written about how to use Mathematica.
I have yet to find one that mentions this problem.  It's even more puzzling
why few if any of the other books discuss this point.

-------------
Regards,
Ted Ersek


  • Prev by Date: Re: PolynomialQ (wrong) behavior ?
  • Next by Date: Re: PolynomialQ (wrong) behavior ?
  • Previous by thread: Automatic Display in MatrixForm
  • Next by thread: Re: Automatic Display in MatrixForm