MathGroup Archive 2009

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

Search the Archive

Re: ReplaceAll and rules from a list v7.0

  • To: mathgroup at smc.vnet.net
  • Subject: [mg104261] Re: [mg104227] ReplaceAll and rules from a list v7.0
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Sun, 25 Oct 2009 01:08:05 -0400 (EDT)
  • Reply-to: hanlonr at cox.net

l = {{1, 1}, {2, 2}, {3, 3}};

Total /@ l

{2,4,6}

Plus @@@ l

{2,4,6}

Plus @@ # & /@ l

{2,4,6}

#[[1]] + #[[2]] & /@ l

{2,4,6}

f[a_, b_] := a + b

f @@@ l

{2,4,6}

a + b /. Thread[{a, b} -> #] & /@ l

{2,4,6}

eqn = x == a + b;

eqn[[2]] /. Thread[{a, b} -> #] & /@ l

{2,4,6}

eqn[[2]] /. Thread /@ (Variables[eqn[[2]]] -> # & /@ l)

{2,4,6}


Bob Hanlon

---- kristoph <kristophs.post at web.de> wrote: 

=============
Hi,

Suppose I have the equation

x=a+b

and the list

l={{1,1},{2,2},{3,3}}

How can I quickly assign the list to the above equation, that is, I
would like to get the following result

{2,4,6}

The first element of each sub-list should be assigned to a and the
second to b.

Thanks in advance.
Kristoph



  • Prev by Date: Re: ReplaceAll and rules from a list v7.0
  • Next by Date: Re: mathematica@linux, character encoding
  • Previous by thread: Re: ReplaceAll and rules from a list v7.0
  • Next by thread: RE: ReplaceAll and rules from a list v7.0