MathGroup Archive 1999

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

Search the Archive

RE: Automatic Display in MatrixForm

  • To: mathgroup at smc.vnet.net
  • Subject: [mg19563] RE: Automatic Display in MatrixForm
  • From: "Ersek, Ted R" <ErsekTR at navair.navy.mil>
  • Date: Wed, 1 Sep 1999 23:07:00 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

More on my latest solution which made matrices display in the equivalent of
MatrixForm, except for an (empty matrix) or (for a matrix of rules).  The
solution also allows one to define MyFunc[x_] which returns a matrix and
display it using the equivalent of StandardForm.

Colin Rose replied:
-----------------------------------------

It's very clever. But it seems a little invasive:  the $Pre
forces an extra evaluation on each and every Input that is undertaken
keeping on setting HiddenSymbols`UseMatrixForm=True.

Is there not a less invasive way, say:

      MyFunc[x] // ListForm

where the addition of ListForm produces the output as
a List, rather than a fancy MatrixForm ?

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

I can't find a less intrusive solution, but the code below is slightly
simpler than what I sent yesterday.

------------------------
In[1]:=
$Pre:=(HiddenSymbols`UseMatrixForm=True;#&)

MakeBoxes[m_?(Function[t,MatrixQ[Unevaluated[t]]&&
(Flatten[t/.(_Rule|_RuleDelayed)->Sequence[]]=!={}),HoldAll]),
StandardForm]/;HiddenSymbols`UseMatrixForm:=
RowBox[{"(",GridBox[Map[Function[t,MakeBoxes[t,StandardForm],HoldAll],Uneval
uated[m],{2}]],")"}]


In[2]:=
MyFunc[x_]:=(HiddenSymbols`UseMatrixForm=False;3 x)


In[3]:=
m={{1,2,1},{1,0,1},{0,0,1}}
MyFunc[m]
m.m

Out[3]=
  1 2 1
  1 0 1
  0 0 1

Out[4]=
{{3,6,3},{3,0,3},{0,0,3}}

Out[5]=
 3 2 4
 1 2 2
 0 0 1



In[6]:=
Solve[x^2-3 x+2==0,x]

Out[6]=
{{x->1},{x->2}}



In[7]:=
{{},{},{}}

Out[7]=
{{},{},{}}
 
 
--------------------
Regards,
Ted Ersek

For Mathematica tips, tricks see 
http://www.dot.net.au/~elisha/ersek/Tricks.html



  • Prev by Date: Re: Asking you how to...
  • Next by Date: Re: Re: Freeing memory in Mathematica
  • Previous by thread: Re: Asking you how to...
  • Next by thread: RE: Automatic Display in MatrixForm