MathGroup Archive 2005

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

Search the Archive

Re: Re: Re: Language vs. Library

Steven, I haven't been following this thread very closely.  Are these rhetorical 
questions to try to prove a point or are you actually wanting an answer to those 
questions?  I'm assuming the latter, ignore my email if that's not the case. :-)

Steven T. Hatton wrote:
> Try this:
> A = Array[a (10#1 + #2) &, {3, 3}]
> v = {x, y, z}
> A.v // MatrixForm
> Clear[A,v];
> A = Array[a (10#1 + #2) &, {3, 3}] // MatrixForm
> v = {x, y, z} // MatrixForm
> A.v
> Why are the results different?

You should analyze the InputForm of the commands you are using.  It may help 
understand what's going on.  The Equal function has very low precedence, so the 
commands you give in postfix notation are being stored as part of the variable 

Compare In[63] with In[69]:

In[59]:= A=Array[a (10#1+#2)&,{3,3}];

In[60]:= v={x,y,z};

In[61]:= InputForm[A]
{{11*a, 12*a, 13*a}, {21*a, 22*a, 23*a}, {31*a, 32*a, 33*a}}

In[62]:= InputForm[v]
{x, y, z}

In[63]:= InputForm[A.v]
{11*a*x + 12*a*y + 13*a*z, 21*a*x + 22*a*y + 23*a*z, 31*a*x + 32*a*y + 33*a*z}


A=Array[a (10#1+#2)&,{3,3}]//MatrixForm;


In[67]:= InputForm[A]
MatrixForm[{{11*a, 12*a, 13*a}, {21*a, 22*a, 23*a}, {31*a, 32*a, 33*a}}]

In[68]:= InputForm[v]

MatrixForm[{x, y, z}]

In[69]:= InputForm[A.v]

MatrixForm[{{11*a, 12*a, 13*a}, {21*a, 22*a, 23*a}, {31*a, 32*a, 33*a}}] .
  MatrixForm[{x, y, z}]

The Dot function can't handle an expression whose head is MatrixForm and, thus, 
returns unevaluated.  To use MatrixForm so that it doesn't affect the definition 
of A and v, but so that it still allows you to view the typeset expression, you 
should do:

MatrixForm[A = ...]
MatrixForm[i = ...]

> Explain this:
> Clear[a, i]
> a[i] = eye;
> i = 3;
> a[3] = three;
> Print["a[i]=", a[i]]
> Clear[i];
> Print["a[i]=", a[i]]

Allow me to rearrange the code a bit for explaining:
First, define your function a, which only returns a result when its argument is 
either i or 3:

In[1]:= a[i] = eye

Out[1]= eye

In[2]:= a[3] = three

Out[2]= three

Let's check what the definitions of a are:

In[3]:= ?? a

a[3] = three

a[i] = eye

Now, define your i variable:

In[4]:= i = 3;

Also, allow me to change your Print statement so it's not misleading:

In[10]:= Print[a[i]];

In In[10], Mathematica first evaluates the value of i, followed by 
a[<value_of_i>], that is, a[3]. According to the definitions of the function a 
(In[3]), a[3] is equal to the string "three".


In[11]:= Clear[i];

In[12]:= Print[a[i]]

The symbol i does not have a value, so nothing is done other than to look up 
a[i] in the list of definitions of function a.  I'm confused, what were you 
expecting as the output of Print[a[i]] after you cleared the value of i?


Igor C. Antonio
Wolfram Research, Inc.

To email me personally, remove the dash.

  • Prev by Date: Re: challenge problem
  • Next by Date: Re: Solving Diophantine Equations
  • Previous by thread: Re: Re: Re: Language vs. Library
  • Next by thread: Re: Language vs. Library