MathGroup Archive 2003

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

Search the Archive

Re: Taking a function as a parameter of a function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg41929] Re: Taking a function as a parameter of a function
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Tue, 10 Jun 2003 04:46:59 -0400 (EDT)
  • Organization: Universitaet Leipzig
  • References: <bbq8jj$d7i$1@smc.vnet.net>
  • Reply-to: kuska at informatik.uni-leipzig.de
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

since x^2+y^2 is Plus[Power[x,2],Power[y,2]]

that matches you pattern. Mathematica can't know
that in
a*x^2+b*y^2

x and y are you variables and a and b not.

Anyway

test[expr_] := Module[{var = Variables[expr], f},
       f = Function[Evaluate[var], expr];
       Table[f @@ (var + {i, i}), {i, 3}]
    ]

will do what you want, as long has you have only
two variables but the nonsens can be increased to
any number of variables with

test[expr_] := Module[{var = Variables[expr], n, f},
       f = Function[Evaluate[var], expr];
       n = Length[var];
       Table[f @@ (var + Table[i, {n}]), {i, 3}]
    ]

Regards
  Jens

JustNImge wrote:
> 
> Hi everyone I'm new to this group and new to Mathematica in general.
> Actually I'm taking a class in it but we've had very little hands on
> experience.
> 
> Anyway, I was wondering if it was possible to take a function as a
> parameter of another function.  What I've been trying to do is make a
> list of x^2+y^2  but increase x and y by one each time so I would have
> (x+1)^2+(y+1)^2 etc.  Actually the function I'm trying to write for my
> class is more complicated than that but I'm trying to figure this out
> first.  When I try to do this, I get:
> In[5]:= test[y1_[x_,y_]]:=Table[y1[x+i,y+i],{i,3}]
> 
> In[6]:= test[x^2+y^2]
> 
>                         2    2          2    2           2    2
> Out[6]= {2 + x  + y , 4 + x  + y , 6 + x  + y }
> 
> Is it just not possible to take x and y as their own parameters like
> this?
> I'm sorry if this has been addressed before but when I browsed
> subjects last night there didn't seem to be anything within the first
> 100.
> Thank you very much for any and all help.
> JustNImge


  • Prev by Date: Re: Strange behavior of Cross[]
  • Next by Date: Re: O(n^2) complexity of ToCycles in Combinatorica
  • Previous by thread: Re: Taking a function as a parameter of a function
  • Next by thread: Getting rid of syntactical sugar