Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2012

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

Search the Archive

Re: MatrixForm odd behaviour

  • To: mathgroup at smc.vnet.net
  • Subject: [mg124515] Re: MatrixForm odd behaviour
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Sun, 22 Jan 2012 07:24:18 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <jf8q80$3iv$1@smc.vnet.net> <jfb3b0$hsm$1@smc.vnet.net>
  • Reply-to: drmajorbob at yahoo.com

Here are a few choices. I like the last one best.

1) We can remove the MatrixForm wrapper whenever we like, as in

mf = MatrixForm;
a = mf@Array[Plus, {2, 3}]
b = mf@Array[Times, {3, 2}]
a[[1]].b[[1]] // mf

(2	3	4
3	4	5)

(1	2
2	4
3	6)

(20	40
26	52)

a[[1]] could have been First[a] or First@a. When Help says something is a  
"wrapper", it means that First removes the "wrapper", and that's ALL it  
means.

Notice that we had to add the wrapper to get the last display.

2) We can never add wrappers at all, except when we want to display a  
matrix.

mf = MatrixForm;
(a = Array[Plus, {2, 3}]) // mf
(b = Array[Times, {3, 2}]) // mf
a.b // mf

(same outputs)

or

3) We can use tf = TraditionalForm the same way we used MatrixForm in the  
first two options. You may like that display better... or maybe you won't.

4) You can choose TraditionalForm as the default display format for output  
cells. That goes badly if you have a matrix with 100 columns, and you're  
only trying to inspect a few cells, as we often do while prototyping and  
debugging.

5) You can use $Post:

$Post = If[MatrixQ@# && Length@Flatten@# < 100,
     TraditionalForm@#, #] &;
a = Array[Plus, {2, 3}]
b = Array[Times, {3, 2}]
a.b
Array[Plus, {5, 75}]
% // tf

Compare the last two outputs at your leisure.

Bobby

On Sat, 21 Jan 2012 04:19:03 -0600, roby <roby.nowak at gmail.com> wrote:

> Dear All.
>
> One can argue a thousend times or even more that MatrixForm is for
> display purpose only.
> On the other hand the user majority (is this a democratic process ?)
> would like to have the possibility to use MatrixForm or a similar
> "Wrapper" in calculations.
> The strange and funny thing is that matrices entered by <Insert><Table/
> Matrix><New> provide a Form similar to MatrixForm which can be used in
> calculations.
> We just neeed a Wrapper for Display which should be ignored for
> calculations, this would ease many things.
> So the only thing we need is a simple way to apply the fuctionality
> provided from matrix input menu to Mathematica matrix expressions, may  
> be this
> exists allready and I just missed soemthing ?
>
> Cheers Robert
>
>
> On 20 Jan., 07:58, "Oleksandr Rasputinov"
> <oleksandr_rasputi... at hmamail.com> wrote:
>> On Thu, 19 Jan 2012 10:11:12 -0000, roby <roby.no... at gmail.com> wrote:
>> > Dear Group
>>
>> > As a similar Question is discussed on the group now.
>>
>> > The following issue:
>>
>> > When entering e.g.:
>> > Dot[MatrixForm[{{1, 0}, {0, 2}}], MatrixForm[{{1, 0}, {0, 2}}]]
>> > Mathematica does not evaluate the Dot operation and displays the two
>> > unchanged
>> > input matrices seperated by a "Dot" each respectively wrapped by
>> > MatrixForm, so far so good (or perhaps not so good).
>>
>> > But if one now marks the most recent Mathematica output, the two "Dot"
>> > seperated matrices and copy and paste's  them into a new Mathematica
>> > cell,
>> > both matrices still are seperated By "Dot", still looking like two
>> > MatrixForm wrapped matrices.
>> > But if you now evaluate the new cell guess what happens: the Dot
>> > operation is performed (despite both matrices seem to be wrapped by
>> > MatrixForm) and the result is displayed (of course not matrixForm
>> > wrapped)
>>
>> > seems highly inconsistent, or ?
>>
>> > other funny things to try:
>> > TraditionalForm[2] * TraditionalForm[2]
>> > or:
>> > Times[TraditionalForm[2], TraditionalForm[2]]
>>
>> > Cheers Robert
>>
>> Perhaps a bit obscure, but not (in my opinion) all that inconsistent  
>> when
>> one understands how these things work.
>>
>> This behaviour comes about because the TagBox generated when MatrixForm  
>> is
>> typeset for output is re-interpreted when given as input. However,
>> MatrixForm does not get converted into a TagBox (unless this is done
>> manually) except when it is typeset for output (the documentation  
>> usually
>> contains phrases like "prints with..." for functions of this sort), so
>> when given in an ordinary expression it stays where it is and can get in
>> the way of operations on expressions wrapped with it. For example, doing
>> the same thing manually:
>>
>> In :=
>> boxes = ToBoxes@MatrixForm@IdentityMatrix[3]
>>
>> Out =
>> < ugly box expression elided >
>>
>> In :=
>> (* ToExpression interprets both strings and boxes *)
>> ToExpression[boxes]
>>
>> Out =
>> {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}
>>
>> One could perhaps argue that the statement in the documentation that
>> "MatrixForm acts as a "wrapper", which affects printing, but not
>> evaluation" is somewhat misleading as it is only true in a fairly narrow
>> sense.
>
>


-- 
DrMajorBob at yahoo.com



  • Prev by Date: Re: Locators disappearing in LocatorPane (although working)
  • Next by Date: exercises: suppress printing of answers
  • Previous by thread: Re: MatrixForm odd behaviour
  • Next by thread: Re: MatrixForm odd behaviour