MathGroup Archive 2004

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

Search the Archive

Re: Applying my function to elements of a vector

  • To: mathgroup at smc.vnet.net
  • Subject: [mg49490] Re: Applying my function to elements of a vector
  • From: BobHanlon at aol.com
  • Date: Thu, 22 Jul 2004 02:44:56 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

v={x1,x2,x3,x4};


f /@ v


{f[x1], f[x2], f[x3], f[x4]}


f[#]& /@ v

{f[x1], f[x2], f[x3], f[x4]}


Or make f Listable

SetAttributes[f, Listable];


f[v]


{f[x1], f[x2], f[x3], f[x4]}


Bob Hanlon

> In a message dated Wed, 21 Jul 2004 11:03:11 +0000 (UTC), <
> gregory.lypny at videotron.ca> writes: Say I've created a function, f[x_], which 
> accepts a single scalar as 
> its argument.   I now want to apply that function to each element of a 
> vector, v, of length n, as in
> 
>      newVector = f[v],
> 
> but I get an error because my function f does not thread over the 
> elements of the vector as do built-in Mathematica functions such as 
> Log[].   How can I get my function to apply to each element of my 
> vector?


  • Prev by Date: Re: If-statement problems
  • Next by Date: Re: simple problem with Map?!?
  • Previous by thread: Applying my function to elements of a vector
  • Next by thread: RE: Applying my function to elements of a vector