       Re: extract elements from a list

• To: mathgroup at smc.vnet.net
• Subject: [mg2862] Re: extract elements from a list
• From: "Stuart C. Schaffner" <sch at mitre.org>
• Date: Sat, 30 Dec 1995 01:01:33 -0500
• Organization: The MITRE Corp.

```Dave Wagner has already ably answered part of your query, but I thought

Yes, you can stick to the FORTRAN subset of Mathematica, but it is
often easier to make at least limited use of the other features of
the language.

Let x be a list of real numbers. We need a list y that is the same
size as x, but where if element i of x is a then the corresponding
element of y should be Line[ { { 5, 25 }, { a, a^2 } } ].
Mathematically, this is a mapping. Then Show[ Graphics[ y ] ].

The following should do this:

x = { 5, 5.5, 5.4, 5.3 };
makeLine[ x_ ] := Line[ { { 5, 25 }, { x, x^2 } } ];
y = Map[ makeLine, x ];
Show[ Graphics[ y ] ];

If you like one-liners, this also works:

Show[ Graphics[ Line[ { { 5, 25 }, { #, #^2 } } ]& /@ x ] ]

Here I have used the & operator to make an inline function
declaration and have used the /@ abbreviation for the Map
function.

Good luck and keep trying.

```

• Prev by Date: Mathematica vs ?
• Next by Date: Mathematica vs ?
• Previous by thread: Re: extract elements from a list
• Next by thread: Re: extract elements from a list