MathGroup Archive 2003

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

Search the Archive

Re: AW: AW: Re: Transpose matrix does not work when MatrixForm is used, why?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg45300] Re: AW: AW: [mg45288] Re: Transpose matrix does not work when MatrixForm is used, why?
  • From: Dr Bob <drbob at bigfoot.com>
  • Date: Mon, 29 Dec 2003 00:22:08 -0500 (EST)
  • References: <AMEOIEPGADIJCHIKPCJIEEHLCHAA.klamser@t-online.de>
  • Reply-to: drbob at bigfoot.com
  • Sender: owner-wri-mathgroup at wolfram.com

No, Andrzej's solution works much better. That way I get to see m in 
MatrixForm every time it is displayed... and still do math with it.

Unprotect[MatrixForm];
MatrixForm /:
   (f_)[MatrixForm[expr_,
      opts___]] := MatrixForm[
     f[expr], opts]
Protect[MatrixForm];
m = MatrixForm[{{1, 2, 3},
     {4, 6, 5}, {9, 8, 7}}]
m
Transpose[m]
Inverse[m]

His solution isn't complete, as this doesn't work yet:

m.Inverse[m]

This takes care of that:

Unprotect[MatrixForm];
MatrixForm /: f_[MatrixForm[a_], MatrixForm[b_]] := MatrixForm[f[a, b]]
Protect[MatrixForm];

But then this still doesn't work:

m.m.m

But this does:

(m.m).m

The behavior I want is nothing more than what Help says is already there 
-- MatrixForm shouldn't affect evaluation.

Bobby

On Sun, 28 Dec 2003 19:49:53 +0100, <Klamser at t-online.de> wrote:

> Hi, for your purpose
>
> (m = { {1, 2, 3}, {4, 5, 6} }) // MatrixForm;
>
> is the best!
>
> Where lies the problem positioning a pair of brackets?
>
> Regards
>
> Peter
>
> -----Ursprüngliche Nachricht-----
> Von: Dr Bob [mailto:drbob at bigfoot.com]
> Gesendet: Sonntag, 28. Dezember 2003 20:42
> An: Klamser at t-online.de; mathgroup at smc.vnet.net
> Betreff: Re: AW: [mg45288] Re: Transpose matrix does not work when
> MatrixForm is used, why?
>
>
> I don't want to see EVERY matrix in MatrixForm -- it takes up too much
> space on my screen, especially for a large matrix, where the screen isn't
> even wide enough to see a row in that format.
>
> Also, MatrixQ will test true for something I think of as a list of lists
> (not a matrix).
>
> Furthermore, MatrixForm is NOT a primitive. Mathematica doesn't have
> primitives as such.
>
> Bobby
>
> On Sun, 28 Dec 2003 18:24:55 +0100, <Klamser at t-online.de> wrote:
>
>> Hi,
>>
>> every modern computer program solves two problems:
>>
>> 1. The main problem (Mathematica solve mathematical problems)
>>
>> 2. Tell the user something about the found solution: The output!
>>
>> Ancient computer program did not! They only solved the problem, the
>> output
>> option was forgotten (ALGOL in the early sixties... ;-) => (because 
>> there
>> was not enough memory...).
>>
>> The MatrixForm primitive is not a mathematical problem, it is one of the
>> second kind. Output has something to do with tradition, not so deep with
>> the
>> problem itself...
>>
>> Therefore the output primitives should not be locked with the problem
>> itself.
>>
>> Some people want to have the same format each Mathematica session.
>> Therefore
>> you find by some experts
>>
>> http://www.verbeia.com/mathematica/tips/Tricks.html
>>
>> or
>>
>> http://www.verbeia.com/mathematica/tips/HTMLLinks/Tricks_174.html
>>
>> $PrePrint=Which[MatrixQ[#],MatrixForm[#],NumberQ[#],#,True,Short[#,50]]&
>>
>> Putting this into your init.m file in the kernel directory, you will 
>> have
>> never again to type //MatrixForm and you never have again to position 
>> the
>> brackets correct:
>>
>> (m = { {1, 2, 3}, {4, 5, 6} }) // MatrixForm;
>>
>> Regards
>>
>> Peter
>>
>>
>> -----Ursprüngliche Nachricht-----
>> Von: Bobby R. Treat [mailto:drbob at bigfoot.com]
>> Gesendet: Sonntag, 28. Dezember 2003 11:11
>> An: mathgroup at smc.vnet.net
>> Betreff: [mg45288] Re: Transpose matrix does not work when MatrixForm is
>> used, why?
>>
>>
>> THANKS for emphasizing that MatrixForm and List are two different
>> heads. That's very, very true -- but rather obvious and not
>> particularly helpful.
>>
>> The issue is that the MatrixForm "wrapper" affects evaluation,
>> contrary to the description in Help. The question is what to do about
>> it.
>>
>> Thanks to Andrzej Kozlowski, we have a short answer that seems to
>> work.
>>
>> Bobby
>>
>> Klamser at t-online.de wrote in message news:<bsjlej$24e$1 at smc.vnet.net>...
>>> Hi,
>>>
>>> why has Santa Claus a red cape on?
>>>
>>> A deer is not a dog is not a dog.
>>>
>>> A MatrixForm Object is not a Matrix.
>>>
>>> m = { {1, 2, 3}, {4, 5, 6} } // MatrixForm;
>>> ??m -> m = MatrixForm[{{1, 2, 3}, {4, 5, 6}}]
>>>
>>> Therefore m[[0]] -> MatrixForm
>>>
>>> But
>>>
>>> (m = { {1, 2, 3}, {4, 5, 6} }) // MatrixForm;
>>> ??m -> m = {{1, 2, 3}, {4, 5, 6}}
>>>
>>> Therefore m[[0]] -> List
>>>
>>> Therefore again:
>>>
>>> A MatrixForm Object is not a Matrix.
>>>
>>> Regards
>>>
>>> Peter Klamser
>>>
>>>
>>> -----Ursprüngliche Nachricht-----
>>> Von: steve_H [mailto:nma124 at hotmail.com]
>>> Gesendet: Mittwoch, 24. Dezember 2003 23:42
>>> An: mathgroup at smc.vnet.net
>>> Betreff:  Re: Transpose matrix does not work when MatrixForm is
>>> used, why?
>>>
>>>
>>> Dr Bob <drbob at bigfoot.com> wrote in message
>>> news:<bsbmsb$lr1$1 at smc.vnet.net>...
>>>
>>> > That may be easier... if we are willing to constantly pay attention 
>>> to
>>> > whether the target of Transpose is "wrapped" in MatrixForm or not.
>>> > (Transpose/@m if it's wrapped, Transpose@m if not.)
>>> >
>>> > But if we want Help's claim that evaluation is not affected to be 
>>> true
>> (it
>>> > currently is NOT), then we have to redefine Transpose, Inverse, etc.
>>> as
>> in
>>> > my example.
>>> >
>>> > Only then would MatrixForm act properly as a wrapper, as intended.
>>> >
>>> > Bobby
>>> >
>>>
>>>
>>> > On Tue, 23 Dec 2003 18:38:10 +0900, Andrzej Kozlowski
>> <akoz at mimuw.edu.pl>
>>> > wrote:
>>> >
>>> > > This of course works, but presumably he would want do this for 
>>> other
>>> > > functions, (e.g. Inverse etc), not just transpose. So it seems to 
>>> me
>> it
>>> > > is easier simply to use Map:
>>> > >
>>> > > m = { {1, 2, 3}, {4, 5, 6} } // MatrixForm
>>> > > Transpose/@m
>>> > >
>>> > > etc.
>>> > >
>>> > > Andrzej Kozlowski
>>> > >
>>>
>>>
>>> Correct Dr Bob,
>>>
>>> But why do we have to resort to all these tricks? Why can't Mathematica
>> just
>>> accept a MatrixForm (or any other representation form) of the object
>>> in its functions (Transpose in this example) just as well as the
>>> list representation?
>>>
>>> Each Mathematica function, where needed, could start by checking if 
>>> this
>>> 'Wrapper' as you call it exists, and converts it to a list
>>> representation (remove the wrapper), and do its thing on the list,
>>> and at the end put the 'wrapper' around the result as needed and
>>> return the result to the user?
>>>
>>> This way one does not have to worry which form of an object one uses,
>>> the representation form or the list form.
>>>
>>> i.e. representation form will be transparent to all Mathematica
>>> functions.
>>
>
>
>




  • Prev by Date: AW: AW: Re: Transpose matrix does not work when MatrixForm is used, why?
  • Next by Date: Mathematica + NETLink + CodeDom- Example 2
  • Previous by thread: AW: AW: Re: Transpose matrix does not work when MatrixForm is used, why?
  • Next by thread: Mathematica + NETLink + CodeDom- Example 2