MathGroup Archive 1998

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

Search the Archive

Re: strange function that defines a function---how do I do it?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg15263] Re: strange function that defines a function---how do I do it?
  • From: "G.C.Levy" <glevy at iol.it>
  • Date: Wed, 30 Dec 1998 01:50:25 -0500
  • Organization: Italia Online
  • References: <75no5e$sgj@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Benjamin Lotto  wrote in message <75no5e$sgj at smc.vnet.net>...
>Working with Mathematica 3.0:
>
>Suppose I define
>
>   makefunction[var_, expr_]:=f[var_?NumberQ]:=NIntegrate[expr,{x,0,1}]
>
>Then I can do something like
>
>   z=x^2
>   makefunction[x,z]
>
>and it will be just as if I typed
>
>   f[x_?NumberQ]:=NIntegrate[x^2,{x,0,1}]
>
>  <..........................>
>OK, now suppose I have a list of variables  x1  up through  xn.  Suppose
>they're in a list:
>
>   list={x1,x2,...,xn}
>
>I want something like "makefunction" above so that when I type
>
>   makefunction[list,expr]
>
>it will be just as if I typed
>
>   f[x1_?NumberQ,x2_?NumberQ,...,xn_?NumberQ]:=expr
>
>analogous to the above.  Can anyone help me?
>
>Thanks in advance.  Y'all out there have been very helpful in the past.


I known nothing about Mathematica 3.0, but in Mathematica 2.2 this works
fine:

makefunction[list_,expr_]:=
    ( Clear[f];
    Evaluate[Apply[f,Pattern[#,_?NumberQ]& /@ list ]] := expr
    )





  • Prev by Date: Consultant Wanted
  • Next by Date: Re: strange function that defines a function---how do I do it?
  • Previous by thread: Re: strange function that defines a function---how do I do it?
  • Next by thread: Re: strange function that defines a function---how do I do it?