MathGroup Archive 2005

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

Search the Archive

Re: Questions on Apply function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg62895] Re: Questions on Apply function
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at Gmail.com>
  • Date: Thu, 8 Dec 2005 00:04:23 -0500 (EST)
  • Organization: The Open University, Milton Keynes, UK
  • References: <dn5ogd$nks$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

PengYu.UT at gmail.com wrote:
> Please look at the following code. I'm wondering the output 1 doesn't
> give me the right answer. 6435-4545 should be 1890. Is there anything
> wrong with input 1? It seems that it is correct, because input 3 works
> well.
> 
> Thanks,
> Peng
> 
> In[1]:=
> Apply[(#+{-6750,6435})&,{{6945,-4545},{6945, -4545}},{1}]
> 
> Out[1]=
> {{195,13380},{195, 13380}}
> 
> In[2]:=
> {-6750,6435}+{6945,-4545}
> 
> Out[2]=
> {195,1890}
> 
> In[3]:=
> Apply[(#+{a,b})&,{{a1,b1},{a2,b2},{a3,b3}},{1}]
> 
> Out[3]=
> {{a+a1,a1+b},{a+a2,a2+b},{a+a3,a3+b}}
> 
Hi Peng,

I think input three does not yield what you are looking for. What you 
would like is, according to input two, {a, b} + {c, d} == {a + c, b + d)
However, inputs one and three return for the first term {a + c, b + c) 
that is {-6750 + 6945, 6435 + 6945} == {195, 13380}.

The function you should use is *Map* as in the following

In[1]:=
Map[(#+{-6750,6435})&,{{6945,-4545},{6945,-4545}}]

Out[1]=
{{195,1890},{195,1890}}

Regards,
/J.M.


  • Prev by Date: Getting good results with NDSolve?
  • Next by Date: Re: Types in Mathematica thread
  • Previous by thread: Re: Questions on Apply function
  • Next by thread: Access control on webMathematica