MathGroup Archive 1999

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

Search the Archive

Re: Automatic Display in MatrixForm

  • To: mathgroup at smc.vnet.net
  • Subject: [mg19245] Re: Automatic Display in MatrixForm
  • From: Bruno Daniel <bruno.daniel at hadiko.de>
  • Date: Wed, 11 Aug 1999 02:06:55 -0400
  • Organization: University of Karlsruhe
  • References: <7ook1l$i37@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hi mates

> This also works for output that doesn't *consist* of a matrix, but 
> *contains* matrices.
This seems to be not a very good idea, since "%" cannot be used on
such an expression. So the following is better:

$Post=If[MatrixQ[#] && Length[#]<18 &&  
         Dimensions[#][[2]]<7,MatrixForm[#],#]&

There's also a check for too large matrices.

------------------------------------------------------------------
Thanks to Ted R. Ersek, I learned that the former version

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

contains a serious bug: In case x has been assigned a value
elsewhere in the Mathematica session, it is substituted on the right
hand side instead of the intended matrix matching the pattern. If
you prefer this version, please correct it to:

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

as Ted Bersek told me. He's right in pointing out that non-delayed
definitions including named patterns are dangerous, since the 
right-hand side of these definitions is evaluated immediately.

So what I learned is the following: Always use ":=" or ":>"
instead of "=" or "->" whenever a named pattern (e.g. "x_") appears
on the left-hand side of the definition/rule. Otherwise your program
will output garbage whenever these names ("x" in this case) are
assigned any values elsewhere in the program.

Ted, thank you very much for your advice!

All comments are appreciated
  Bruno


  • Prev by Date: Re: SetDirectory
  • Next by Date: Re: Defining a function P[A_ | B_]:=f[A,B] overriding Alternatives
  • Previous by thread: RE: Automatic Display in MatrixForm
  • Next by thread: Re: Re: Automatic Display in MatrixForm