Re: Taking a function as a parameter of a function
- To: mathgroup at smc.vnet.net
- Subject: [mg41896] Re: Taking a function as a parameter of a function
- From: justnimge at angelfire.com (JustNImge)
- Date: Sun, 8 Jun 2003 06:45:59 -0400 (EDT)
- References: <bbq8jj$d7i$1@smc.vnet.net> <bbrpfo$j7k$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
eduault <eduault at yahoo.com> wrote in message news:<bbrpfo$j7k$1 at smc.vnet.net>...
>
> In your example, x^2+y^2 is considered by Mathematica as the expression
> "Plus[Power[x, 2], Power[y, 2]" ,
> so the y1 parameter will be mapped to the "Plus" (+) function, x to
> "Power[x, 2]", and y to "Power[y, 2]".
> y1[x+i,y+i] is evaluated as Plus[ Power[x, 2]+i , Power[y, 2]+i ], or in a
> simpler form as x^2+y^2+2*i.
>
> You should try :
>
> In[46]:= f[x_, y_] := x^2 + y^2;
> In[47]:= test[f_, x_, y_] := Table[f[x + i, y + i], {i, 3}];
> In[48]:= test[f, x, y]
> Out[49]= {(1 + x)^2 + (1 + y)^2, (2 + x)^2 + (2 + y)^2, (3 + x)^2 + (3 +
> y)^2}
>
> ou with a pure function (#1^2 + #2^2 &) instead of f:
>
> In[50]:= test[f_, x_, y_] := Table[f[x + i, y + i], {i, 3}];
> In[51]:= test[#1^2 + #2^2 &, x, y]
> Out[52]= {(1 + x)^2 + (1 + y)^2, (2 + x)^2 + (2 + y)^2, (3 + x)^2 + (3 +
> y)^2}
>
>
> In[53]:= Expand[%]
> Out[54]= {2 + 2*x + x^2 + 2*y + y^2, 8 + 4*x + x^2 + 4*y + y^2, 18 + 6*x +
> x^2 + 6*y + y^2}
>
>
> If this code is not what you expect, you should give a complete example,
> saying what what the "y1_[x_,y_]]" you really use is, what the y1, x and y
> are in this expression, and what the expected transformation / result is.
This worked perfectly, thank you very much. =)
JustNImge