MathGroup Archive 1998

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

Search the Archive

Re: Function as an argument to a function


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