Re: General--Difficulties in Understanding Mathematica Syntax
- To: mathgroup at smc.vnet.net
- Subject: [mg69043] Re: General--Difficulties in Understanding Mathematica Syntax
- From: AES <siegman at stanford.edu>
- Date: Mon, 28 Aug 2006 02:54:43 -0400 (EDT)
- Organization: Stanford University
- References: <ecrbsu$pc5$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
In article <ecrbsu$pc5$1 at smc.vnet.net>,
Bill Rowe <readnewsciv at earthlink.net> wrote:
> lBut the code with Map is simpler since I do not need to worry about
> indexing. For example, a typical error when coding with For loops to index an
> array is to be one off, i.e., using say greater as the stopping criteria when
> it should have been greater than or equal. Since indexing is never explicitly
> coded with Map, this error cannot happen.
I do agree with the underlying point in this comment. The gimmick I've
learned to always use with indexing is more or less the following. If
I'm doing a problem that involves say stepping over values of an
independent variable x ranging from 0 to xmax -- or more generally from
xmin to xmax -- I start by defining an x array using
xArray = Table[x, {xmin, xmax, (xmax-xmin)/nSteps]} ]
and then never touch a specific index or use [[ ]] notation again.
Plotting of results is done using
ListPlot[Transpose[{ xArray, resultArray} ]