       Re: Why is Mathematica assuming k==l and how do I make it

• To: mathgroup at smc.vnet.net
• Subject: [mg92710] Re: Why is Mathematica assuming k==l and how do I make it
• From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
• Date: Sat, 11 Oct 2008 06:43:37 -0400 (EDT)
• Organization: The Open University, Milton Keynes, UK
• References: <gci2il\$td\$1@smc.vnet.net> <gcn4a5\$75e\$1@smc.vnet.net>

```mariam wrote:

*snip*

> i am new to mathematica and learning about some codes needed in my
> projects.
> i want to know that:
> 1)
>
> Do[{
>   	ileng[i1] = Length[amplist[i1]],
>
> 	Do[{
>     	Print["Processing amp[",i1,",",i2,"]"],
>     	If[i1===2,{amp[i1,i2] = amplist[i1][[i2]][]}, {amp[i1,i2] =
> amplist[i1][[i2]][]
> 											  }],
> ---------------------------------- and so on.
>  What does amp[i1,i2] = amplist[i1] [[i2]] [] mean? I mean any
> f[i.j]=g[i] [[j]] [[k]]
> I am confused about the double-brackets used  [[----]].
>
> 2) in another expression,
> itwo = StringPosition[jproc,"2"][[1,1]]
>
> what for [[ x, y]] is used?

The notation [[__]] is a shortcut for the built-in functions *Part*,
which works to some extent like an index for an array, except that you
can iterate over any kind of expression.

In:= lst = {{a, b, c}, {3, 5, 1}};

In:= lst[[2, 2]]

Out= 5

In:= Do[Print[lst[[x, y]]], {x, 2, 1, -1}, {y, 3, 1, -1}]

During evaluation of In:= 1

During evaluation of In:= 5

During evaluation of In:= 3

During evaluation of In:= c

During evaluation of In:= b

During evaluation of In:= a

In:= poly = a x^3 + b x^2 + c x + d

Out= d + c x + b x^2 + a x^3

In:= poly[]

Out= b x^2

In:= poly[[3, 2]]

Out= x^2

In:= poly[[3, 2, 2]]

Out= 2

You should have a look at the following (short) documents:

"Manipulating Elements of Lists"
http://reference.wolfram.com/mathematica/tutorial/ManipulatingElementsOfLists.html

"Getting Pieces of Lists"
http://reference.wolfram.com/mathematica/tutorial/GettingPiecesOfLists.html

"Parts of Expressions"
http://reference.wolfram.com/mathematica/tutorial/PartsOfExpressions.html

"Manipulating Lists by Their Indices"
http://reference.wolfram.com/mathematica/tutorial/ManipulatingListsByTheirIndices.html

"Part ([[...]])"
http://reference.wolfram.com/mathematica/ref/Part.html

Regards,
-- Jean-Marc

```

• Prev by Date: Re: Re: Why is Mathematica assuming k==l and how do I
• Next by Date: Re: Overlapping binning of differences of two lists
• Previous by thread: Re: Why is Mathematica assuming k==l and how do I make it
• Next by thread: Re: Why is Mathematica assuming k==l and how do I make it