Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1998
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1998

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

Search the Archive

Re: Function as an argument to a function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg13829] Re: Function as an argument to a function
  • From: "Allan Hayes" <hay at haystack.demon.cc.uk>
  • Date: Sat, 29 Aug 1998 04:41:08 -0400
  • References: <6s5msa$ccu@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Jani Eerikki Lakkakorpi wrote in message <6s5msa$ccu at smc.vnet.net>...

>I want to pass a function as an argument to a function I am developing.
>For example: Myfunction[Exp[x]]
>
>I would like Myfunction to return the value of it's parameter function
>when (for example) x=1.
>
>Here's what I have tried:
>
>Myfunction[f_] :=
> f[1]
>
>Doesn't work. Any suggestions??
>--

The input f needs to be a function. For example

Myfunction[f_] :=
f[1.2]

Myfunction[Exp[#^2]&]

4.2207

Here is a variant for expressions (it also allows the value of x to be
input)

MyExpression[expr_,x_, v_]:=
 Block[{x = v},expr]

Clear[x]

MyExpression[Exp[x^2],x, 1.2]

4.2207

------------------------------------------------------------- Allan
Hayes
Training and Consulting
Leicester UK
http://www.haystack.demon.co.uk
hay at haystack.demon.co.uk
voice: +44 (0)116 271 4198
fax: +44(0)116 271 8642



  • Prev by Date: Re: FeynArts
  • Next by Date: Re: Mathematica
  • Previous by thread: Re: Function as an argument to a function
  • Next by thread: Re: Function as an argument to a function