Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Assume that;

w[n_] :=Expand[Sum[Binomial[n - k - 1, k]*(-1)^k*A^(n - 2*k - 1), {k, 0, n - 1}]]
f[x_,y_, z_]:=PolynomialRemainder[(w[z] - 1)*(w[y] - 1), (w[x] - 1), A]

According to the above definitions, the function f depends on x,y,z and A. I want to have a new function only depends on A for any x,y,z. For example, when i put some values for x,y,z, i want a function such

g[A_]:=.........How can i obtain?

Thanks...

share|improve this question

1 Answer 1

up vote 4 down vote accepted

One possibility:

f[x_, y_, z_] := 
   Block[{A}, 
     Function @@ {A,PolynomialRemainder[(w[z] - 1)*(w[y] - 1), (w[x] - 1), A]}
   ]

When you call f, the result would be a pure function depending on A only, with the values x, y and z embedded into its body. I used Function @@ {} idiom to allow the body to evaluate, so that the evaluation of PolynomialRemainder and w is done only once, at definition-time.

For example:

f[4, 5, 16]

(* Function[A, 4 + 2 A - 2 A^2] *)

and you can now store this function in a variable and apply it many times. Technically, what you asked for is how one can create a closure - a function which carries some of the surrounding environment in its body. In this case, it was a little more tricky since I chose to perform some evaluation at definition-time as an optimization.

As a side note, it is best to not use capital letters for variables, since names starting with capital letters may collide with the system names.

share|improve this answer
    
Thank you for your response. In the case x=4, y=5, z=16 and in order to obtain a list for 0<A<10, what will i do? –  MATIRMAK Apr 10 '13 at 23:23
    
@Nurettinırmak myFun = f[4, 5, 16]; Map[myFun, Range[9]]. –  Leonid Shifrin Apr 10 '13 at 23:27
    
Thank you. i am new user. Therefore, i can ask very easy questions :) –  MATIRMAK Apr 10 '13 at 23:32
    
@Nurettinırmak Glad I could help, and thanks for the accept. I would still suggest to spend some time and get familiar with the basics. The question you asked was not quite a basic one, so this does not apply to the case at hand, but be aware that very basic (RTFM - like) questions are frowned upon here. –  Leonid Shifrin Apr 10 '13 at 23:35
    
+1 Leonid: Another "easy" question from the OP for you to enjoy mathematica.stackexchange.com/q/22807/193 –  belisarius Apr 11 '13 at 2:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.