MathGroup Archive 2003

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: defining a transform from two lists

  • To: mathgroup at smc.vnet.net
  • Subject: [mg40856] Re: [mg40837] defining a transform from two lists
  • From: Bobby Treat <drmajorbob+MathGroup3528 at mailblocks.com>
  • Date: Tue, 22 Apr 2003 06:45:40 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

p1=Table[{n@i,a@i},{i,1,5}]

p2=Table[{n@i,b@i},{i,1,5}]

Here's the simple way, but it involves recomputing n, a, and b values:

p3=Table[{n@i,f[a@i,b@i]},{i,1,5}]

Here are three methods:

h[{{n_,a_},{n_,b_}}]:={n,f[a,b]}
h/@Transpose@{p1,p2}

or

Transpose@{p1,p2}/.{{n_,a_},{n_,b_}}:>{n,f[a,b]}

or

hh[{n_, a_}, {n_, b_}] := {n, f[a, b]}
Thread[hh[p1, p2]]

The second n_ could be replaced by _ in all three cases, and that would 
speed up the pattern matching -- if there's no danger of the function 
being applied inappropriately.

Bobby

-----Original Message-----
From: Nathan Moore <nmoore at physics.umn.edu>
To: mathgroup at smc.vnet.net
Subject: [mg40856] [mg40837] defining a transform from two lists

Suppose I have two lists of similar length,
    p1={n[i],a[i]}
and
    p2 = {n[i],b[i]}
and I'd like to create a new list,
    p3 = { n[i], f[ a[i], b[i] ] }
if the new list comes from one parent list then it is relatively simple 
to
write and apply a transform w/ map like
    h[{x_,y_}]:={x,f[y]}
    newlist = h/@list or = Map[h,list]
but two parent lists confuse me

thanks again!

Nathan Moore,
University of Minnesota Physics


  • Prev by Date: Re: Finding derivatives of a list?
  • Next by Date: Re: data fitting function
  • Previous by thread: Re: defining a transform from two lists
  • Next by thread: RE: defining a transform from two lists