MathGroup Archive 1999

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

Search the Archive

Re: Linear Algebra `MatrixManipulation`

  • To: mathgroup at smc.vnet.net
  • Subject: [mg20017] Re: Linear Algebra `MatrixManipulation`
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Sat, 25 Sep 1999 02:40:44 -0400
  • References: <7se6t8$qsv@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Robert F. Scheyder <scheyder at math.upenn.edu> wrote in message
news:7se6t8$qsv at smc.vnet.net...
> Hi,
>
> Maybe someone can help me.
>
> When I define two matrices such as G={{1,2},{3,4}}  and H={{5,6,},{7,8}}
and
> then perform an operation such as multiplication, I get the correct
result.
> But, if I add  MatrixForm to each matrix first and then perform the
> operation, the operation is not evaluated.  The output is simply two
> Standard Form expressions with no result.
>
> I appreciate any help.
>
> Robert
>
> --
> ===================================================
> Robert F. Scheyder
> Department of Mathematics
> University of Pennsylvania
> Philadelphia, PA 19104
> scheyder at math.upenn.edu
>
> "Life is a Battlefield..."
>     -with apologies to Pat Benatar
>



Robert,

Firstly, if you use menu Cell > Default Output FormatType> TraditionalForm
then all matrices will be displayed in 2D form - you can alter more
precisely with Cell > Convert To > Traditional Form.

The key to understanding your particular problems is the following behaviour

In[1]:=
MatrixForm[{{1, 2}, {3, 4}}]

Out[1]//MatrixForm=
1   2

3   4

Mathematica *diaplays* MatrixForm[{{1, 2}, {3, 4}}] (and tells us this with the cell
label Out[1]//MatrixForm=) but it *stores* {{1, 2}, {3, 4}} as the value of
Out[1]. Thus

In[2]:=
Out[1](*otherwise %*)

Out[2]=
{{1, 2}, {3, 4}}


MatrixForm is a "wrapper" (evaluate $OutputForms to get the list of them)
and wheneverWrapper[expr] is sent for display and for storing as a value of
Out[n] , then Wrapper[expr] is displayed but expr is stored as the value of
Out[n]. We say that (outer) wrappers ae stripped off.

Now, if we enter
 G1 = MatrixForm[{{1, 2}, {3, 4}} ]
then MatrixForm[{{1, 2}, {3, 4}} ] will be stored as the value of G1 and
passed on (as the value of G1 = MatrixForm[{{1, 2}, {3, 4}} ]) for display
and storing as the value of Out[3].
So we get

In[3]:=
G1 = MatrixForm[{{1, 2}, {3, 4}} ]

Out[3]//MatrixForm=
1   2

3   4

In[4]:=
Out[3] (*otherwise %*)

Out[4]=
{{1, 2}, {3, 4}}

and

In[5]:=
?G1

Global`G1
G1 = MatrixForm[{{1, 2}, {3, 4}}]

This wrapper MatrixForm round the value of G1 stops the following addition
being evaluated (as well as giving the 2D display)

In[6]:=
a + G1

Out[6]=
a + 1   2

    3   4

Now, if instead we enter
 MatrixForm[ G1 ={{1, 2}, {3, 4}} ]
then {{1, 2}, {3, 4}}  will be stored as the value of G1; passed on to
MatrixForm (as the value of G1 = {{1, 2}, {3, 4}} ), and then
MatrixForm[{{1, 2}, {3, 4}}] will be passed on for display and storing as
the value of Out[3].
So we get

In[7]:=
(G2 = {{1, 2}, {3, 4}}) // MatrixForm

Out[7]//MatrixForm=
1   2

3   4

In[8]:=
G2

Out[8]=
{{1, 2}, {3, 4}}

and

In[9]:=
a + G2

Out[9]=
{{1 + a, 2 + a}, {3 + a, 4 + a}}

NOTES

1) Nested outer wrappers are all effective; only the first is shown in the
cell label; but all  are stripped off for storing:

In[10]:=
TeXForm[MatrixForm[{{1, 2}, {3, 4}}]]

Out[10]//TeXForm=
\matrix{ 1 & 2 \cr 3 & 4 \cr  }

In[11]:=
%

Out[11]=
{{1, 2}, {3, 4}}

2) Wrappers inside non-wrappers alter rhe display but are not stripped of
for storing

In[12]:=
a + MatrixForm[{{1, 2}, {3, 4}}]

Out[12]=
a + 1   2

    3   4

In[13]:=
%

Out[13]=
a + 1   2

    3   4

Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565






  • Prev by Date: Remote shell with X-window emulator
  • Next by Date: Re: Select cell
  • Previous by thread: Re: Linear Algebra `MatrixManipulation`
  • Next by thread: Re: Linear Algebra `MatrixManipulation`