Re: A Bug / Feature
- To: mathgroup@smc.vnet.net
- Subject: [mg12589] Re: A Bug / Feature
- From: "Allan Hayes" <hay@haystack.demon.cc.uk>
- Date: Mon, 25 May 1998 14:25:00 -0400
- References: <6k7e81$1n1@smc.vnet.net>
Ersek_Ted%PAX1A@mr.nawcad.navy.mil wrote in message <6k7e81$1n1@smc.vnet.net>... ---------------------------------------------------------------------- I don't know if this is a bug or a feature, but I don't like what I get for {Head[expr], Head[%n]} in the lines below! In[1]:= m1=MatrixForm[{{1,2},{3,4}}] Out[1]//MatrixForm= (* output deleted *) In[2]:= {Head[m1],Head[%1]} Out[2]= {MatrixForm, List} ........... several analogous examples deleted ......... Shouldn't they both have the same head? Makes no sense to me. Ted Ersek ------------------------------------------------------------------- Ted, here are some notes on this issue (it is a feature!) With In[1]:= mat ={{1,2},{3,4}}; When m1=MatrixForm[mat] is entered (see below), ml is assigned the value of MatrixForm[mat], which is {{1,2},{3,4}}, with MatrixForm wrapped round it, that is MatrixForm[{{1,2},{3,4}}]. Out[2] might be expected to get the value of m1=MatrixForm[mat], that is , again, MatrixForm[{{1,2},{3,4}}]. But the wrapper MatrixForm is stripped off and Out[n] is assigned {{1,2},{3,4}}. In[2]:= m1=MatrixForm[mat] Out[2]//MatrixForm= 1 2 3 4 The cell label tells us that we are being shown Out[2] with MatrixForm wrapped round it, not Out[2]. Check on the value of m1: In[3]:= m1 Out[3]//MatrixForm= 1 2 3 4 But here is the value of Out[2] (no MatrixForm) In[4]:= %2 Out[4]= {{1, 2}, {3, 4}} This stripping is only at the outside of the expression. For example, in the following MatrixForm is retained and prevents addition taking a inside. In[5]:= a +MatrixForm[mat] Out[5]= a + 1 2 3 4 To avoid some of these problems we can use In[6]:= MatrixForm[m1=mat] Out[6]//MatrixForm= 1 2 3 4 Then we get In[56]:= m1 Out[56]= {{1,2},{3,4}} ------------------------------------------------------------- Allan Hayes Training and Consulting Leicester UK http://www.haystack.demon.co.uk hay@haystack.demon.co.uk voice: +44 (0)116 271 4198 fax: +44(0)116 271 8642