Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

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

Search the Archive

RE: Applying my function to elements of a vector

  • To: mathgroup at
  • Subject: [mg49494] RE: [mg49464] Applying my function to elements of a vector
  • From: "Ellis, George" <George.Ellis at Cognos.COM>
  • Date: Thu, 22 Jul 2004 02:45:03 -0400 (EDT)
  • Sender: owner-wri-mathgroup at

Something like this?

f[x_] := x^2
vec = {1, 2, 3};
Map[f[#] &, vec]



-----Original Message-----
From: Gregory Lypny [mailto:gregory.lypny at] 
To: mathgroup at
Subject: [mg49494] [mg49464] Applying my function to elements of a vector

Hello everyone,

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?


       This message may contain privileged and/or confidential information.  If you have received this e-mail in error or are not the intended recipient, you may not use, copy, disseminate or distribute it; do not open any attachments, delete it immediately from your system and notify the sender promptly by e-mail that you have done so.  Thank you. 

  • Prev by Date: AW: Plotting a contour plot with cylindrical co-ordinates
  • Next by Date: RE: If-statement problems
  • Previous by thread: RE: Applying my function to elements of a vector
  • Next by thread: Simplify doesn't simplify SparseArrays