[Date Index]
[Thread Index]
[Author Index]
RE: Modify a list of pure functions
*To*: mathgroup at smc.vnet.net
*Subject*: [mg70839] RE: [mg70812] Modify a list of pure functions
*From*: "David Park" <djmp at earthlink.net>
*Date*: Sat, 28 Oct 2006 23:38:46 -0400 (EDT)
What about...
f = Sin[#] &;
Function /@ Table[i Part[f, 1], {i, 1, 5}]
{Sin[#1] &, 2 Sin[#1] &, 3 Sin[#1] &, 4 Sin[#1] &, 5 Sin[#1] &}
That is, deconstruct the function, modify it, and then reconstruct the
functions.
David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/
From: . [mailto:ggroup at sarj.ca]
To: mathgroup at smc.vnet.net
Hi all,
I have a problem where I need to build up a list of pure functions that
have been modified from a base pure function. I'm not having much luck
in getting it to work correctly, and was wondering if anyone had some
good ideas. A toy version of the problem is:
f = Sin[#]&
listF = Table[(i f[##])&, {i, 5}]
What I'd hope to get is listF containing:
{Sin[##]&, (2 Sin[##])&, (3 Sin[##])&, (4 Sin[##])&, (5 Sin[##])&}
But instead, I get something where neither i nor f have been evaluated.
As I say, this is a toy example. One thing that does partially work
for the toy case, but does not seem to work for more complicated
situations is to use ReplaceAll:
listF2 = Table[{j f[##])& /. j->i, {i,5}]
This does give:
{1 f[##1] &, 2 f[##1] &, 3 f[##1]&, 4 f[##1] &, 5 f[##1] &}
However, all that has been done is the index has been inserted; no
significant evaluation seems to have occurred. So this method doesn't
work in more complicated situations. For example, suppose insted of
using the index i directly, it actually referred to a list:
coeffs = Reverse[ Range[5] ];
listF3 = Table[ (coeffs[[j]] f[##]) & /. j->i, {i, 5}]
This just gives:
{coeffs[[1]]*f[##1] & , coeffs[[2]]*f[##1] & , coeffs[[3]]*f[##1] & ,
coeffs[[4]]*f[##1] & , coeffs[[5]]*f[##1] & }
Which is no good if coeffs is a temporary variable.
Any suggestions would be most appreciated. Thanks!
Prev by Date:
**Re: Modify a list of pure functions**
Next by Date:
**Re: Modify a list of pure functions**
Previous by thread:
**Re: Modify a list of pure functions**
Next by thread:
**Re: Modify a list of pure functions**
| |