MathGroup Archive 1999

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

Search the Archive

Re: Automatic Display in MatrixForm

  • To: mathgroup at smc.vnet.net
  • Subject: [mg19259] Re: [mg19206] Automatic Display in MatrixForm
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Thu, 12 Aug 1999 01:24:18 -0400
  • References: <7or4k5$13j@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Ted,

Two comments: A) and B)
I show the outputs in InputForm and indented
(of course we can always use TraditionalForm: Cell>Default Output
Format>TraditionalForm)

A) There are still problems:

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

mtrx = {{2, 0, 0}, {0, -1, 0}, {0, 0, 3}}

    MatrixForm[{{2, 0, 0}, {0, -1, 0}, {0, 0, 3}}]

mtrx.a

    MatrixForm[{{2, 0, 0}, {0, -1, 0}, {0, 0, 3}}] . a

% /. a -> mtrx

    MatrixForm[MatrixForm[{{2, 0, 0}, {0, -1, 0},
         {0, 0, 3}}]] . MatrixForm[{{2, 0, 0}, {0, -1, 0},
        {0, 0, 3}}]

The MatrixForm wrappers prevent the Dot product.

B) Perhaps a more general solution is as follows (where  MatrixForm is first
replaces by Identity  to allow evaluation, and is then replaced
appropriately). I await a list of problems with this also!

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

mtrx = {{2, 0, 0}, {0, -1, 0}, {0, 0, 3}}

    MatrixForm[{{2, 0, 0}, {0, -1, 0}, {0, 0, 3}}]

mtrx.a

    MatrixForm[{{2, 0, 0}, {0, -1, 0}, {0, 0, 3}}] . a

% /. a -> mtrx

    MatrixForm[{{4, 0, 0}, {0, 1, 0}, {0, 0, 9}}]



Ersek, Ted R <ErsekTR at navair.navy.mil> wrote in message
news:7or4k5$13j at smc.vnet.net...
> 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: Lists to mask other lists
  • Next by Date: Q: How to take an expr from Hold[expr] wrap without evaluate it?
  • Previous by thread: RE: Automatic Display in MatrixForm
  • Next by thread: Re: Automatic Display in MatrixForm