RE: Functional programming
- To: mathgroup at smc.vnet.net
- Subject: [mg39028] RE: [mg39015] Functional programming
- From: "David Park" <djmp at earthlink.net>
- Date: Sat, 25 Jan 2003 01:24:21 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Zachary,
First, don't overlook the humble Table statement.
Table[f[x, 4], {x, 1, 4}]
{f[1, 4], f[2, 4], f[3, 4], f[4, 4]}
Other methods to generate evenly spaced arguments...
Array[f[#, 4] &, 4]
{f[1, 4], f[2, 4], f[3, 4], f[4, 4]}
f[#, 4] & /@ Range[4]
{f[1, 4], f[2, 4], f[3, 4], f[4, 4]}
For an oddball list of first arguments.
f[#, 4] & /@ {1, 3, 4, 7, x}
{f[1, 4], f[3, 4], f[4, 4], f[7, 4], f[x, 4]}
MapThread[f[#, 4] &, {{1, 3, 4, 7, x}}]
{f[1, 4], f[3, 4], f[4, 4], f[7, 4], f[x, 4]}
Or to generate an oddball values for both arguments.
MapThread[f[#1, #2] &, {{1, 3, 4, 7, x}, {2, 3, 4, 9, x}}]
{f[1, 2], f[3, 3], f[4, 4], f[7, 9], f[x, x]}
David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/
From: Zachary Turner [mailto:_NOzturner0826SPAM_ at hotmail.com]
To: mathgroup at smc.vnet.net
I have a function f[a_,b_] defined some way. i want to fix one argument,
and then generate an array of values where the other argument varies. How
can I do this?
For example, I want:
{f[1, 4], f[2, 4], f[3, 4], f[4, 4]}
Is there an easy way to do this?
Thanks