MathGroup Archive 2012

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

Search the Archive

Re: How to convert the expression 3*x to a function in Mathematica?


Note that Function has the attribute HoldAll

Attributes[Function]

{HoldAll, Protected}

convert[f_] := Function[
  Evaluate[Cases[f,
    _Symbol?(! NumericQ[#] &), Infinity]],
  Evaluate[f]]

f = 3*x;

g = convert[f]

Function[{x}, 3 x]

g[z]

3 z

f = Sin[x + y];

g = convert[f]

Function[{x, y}, Sin[x + y]]

g[r, s]

Sin[r + s]


Bob Hanlon


On Sun, Oct 21, 2012 at 2:10 AM,  <pedro_fr_22 at hotmail.com> wrote:
> In doing a program in Mathematica that receives an expression called f and converts it to a function. However the command Function[x,f] doesn't work, what do I do?
>



  • Prev by Date: Re: Separating functions
  • Next by Date: Re: How to convert the expression 3*x to a function in
  • Previous by thread: How to convert the expression 3*x to a function in Mathematica?
  • Next by thread: Re: How to convert the expression 3*x to a function in