Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following code:

fbasic = A + R + Z*Z *Z*Z;
f[A_, Z_, R_] := fbasic + R;
f[0, 2, 3]

The answer I am getting is

3 + A + R + Z^4

Which is not what I want because the fbasic is not replaced by the expression. How can I do that?

share|improve this question
Try using Set rather than SetDelayed. – b.gatessucks Aug 18 '13 at 14:45
Thanks so much. It works. Could you give me more information about the difference between := and =? I really appreciate your help. – user8551 Aug 18 '13 at 14:52
By the way, if I use Set rather than SetDelayed, how can I call this function later? Because "fbasic"can be an arbitrary function. – user8551 Aug 18 '13 at 15:04

For example, use Set Delayed and arguments

fbasic[a_, z_, r_] := a + r + z^4;
f[a_, z_, r_] := fbasic[a, z, r] + r;
f[0, 2, 3]

Another option is:

fbasic = aa + rr + zz^4;
f[a_, z_, r_] := Evaluate[fbasic /. {rr -> r, aa -> a, zz -> z}] + r;
f[0, 2, 3]


fbasic = aa + rr + zz^4;
f[a_, z_, r_] := Block[{rr = r, aa = a, zz = z}, fbasic + r]
f[0, 2, 3]
share|improve this answer
Thanks for your kind help. But in my code, there is a loop. Sometimes I don't the expression of "fbasic" which is calculated by the previous one. How I define this kind of function? – user8551 Aug 18 '13 at 15:12
@user8551 That seems another kind of question. Could you edit your question specifying the problem a little bit more? – Dr. belisarius Aug 18 '13 at 15:18
Omit Evaluate? – Michael E2 Aug 18 '13 at 15:22
The concept of my code is: I write a function to calculate the multidimensional numerical integration.The input is a function. The output is the value which is the numerical integration. The first part of the code is 'FNintegration[fbasic_] := f[A_, Z_, R_] := fbasic;.....' . fbasic is an arbitrary function of A,Z and R.I need to get the value with different A Z and R. That is why I define another function f[A_, Z_, R_]. I want to call this function later. Thanks for your kind help. – user8551 Aug 19 '13 at 2:25

Your Answer


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.