0

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?

m_goldberg
  • 107,779
  • 16
  • 103
  • 257

1 Answers1

2

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]

Or:

fbasic = aa + rr + zz^4;
f[a_, z_, r_] := Block[{rr = r, aa = a, zz = z}, fbasic + r]
f[0, 2, 3]
Dr. belisarius
  • 115,881
  • 13
  • 203
  • 453
  • 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
  • 1
    @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 02:25