[Date Index]
[Thread Index]
[Author Index]
Re: Behavior of Array[]
*To*: mathgroup at smc.vnet.net
*Subject*: [mg19479] Re: Behavior of Array[]
*From*: paulh at wolfram.com (P.J. Hinton)
*Date*: Sat, 28 Aug 1999 15:53:07 -0400
*Organization*: "Wolfram Research, Inc."
*References*: <7q20js$q91@smc.vnet.net>
*Sender*: owner-wri-mathgroup at wolfram.com
In article <7q20js$q91 at smc.vnet.net>, jslater at cs.wright.edu (Joseph C. Slater) writes:
>I've been using Mathematica for many years and one thing still puzzles me.
>Elements of the array defined by the variable 'a' can be obtained using
>a[[i,j]]=expression. However, the command Array creates arrays comprised
>of elements named in the form 'a[i,j]'. Note the single brackets.
>Everything I see in the Mathematica book about brackets says that these
>are functions. This seems inconsistant to me. Shouldn't they be listed as
>'a[[i,j]]' until they are defined? What are the single brackets supposed
>to mean if not elements of the array 'a'?
Single square brackets delimit the elements of a Mathematica
expression.
h[e1, e2, ..., en]
Since it is possible to associate rules that replace certain classes of
expressions with other expressions, the most common interpretation of
single square brackets is to indicate evaluation of a function (h)
for the sequence of arguments e1, e2, ..., en.
The use of double square brackets is a short form of the function
Part[], which is used to extract elements from an expression.
For your example, a[i, j] simply denotes an expression which has
a Symbol head named a and Symbol elements named i and j. In writing
a[[i, j]], you are telling the kernel to extract element of the
expression a that is at the position i j.
This example demonstrates how single and double brackets serve
different purposes.
In[1]:= q = Array[a, {2,2}]
Out[1]= {{a[1, 1], a[1, 2]}, {a[2, 1], a[2, 2]}}
In[2]:= a[2, 1] = 3
Out[2]= 3
In[3]:= q
Out[3]= {{a[1, 1], a[1, 2]}, {3, a[2, 2]}}
In[4]:= q[[2,1]]
Out[4]= 3
--
P.J. Hinton
Mathematica Programming Group paulh at wolfram.com
Wolfram Research, Inc.
Disclaimer: Opinions expressed herein are those of the author alone.
Prev by Date:
**Re: ReplaceAll in If Statement**
Next by Date:
**GaussianQuadrature and truncated normal**
Previous by thread:
**Re: Behavior of Array[]**
Next by thread:
**Mathematica on linux help**
| |