Re: extract elements from a list

• Subject: [mg2862] Re: extract elements from a list
• From: sch at mitre.org ("Stuart C. Schaffner")
• Date: 30 Dec 1995 03:40:42 -0600
• Approved: usenet@wri.com
• Distribution: local
• Newsgroups: wri.mathgroup
• Organization: The MITRE Corp.
• Sender: daemon at wri.com

```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: Re: Re: FindMinimum and NIntegrate
• Previous by thread: Re: extract elements from a list
• Next by thread: Polar Contour Plots