MathGroup Archive 1998

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

Search the Archive

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


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}]

In fact, entering

   ?f

at this point yields

   "Global`f"

   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.


  • Prev by Date: Re: Mathematica <-> Java???
  • Next by Date: Re: rician random number
  • Previous by thread: Partial Least Squares (PLS)
  • Next by thread: Re: strange function that defines a function---how do I do it?