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?
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?
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]
Setrather thanSetDelayed. – b.gates.you.know.what Aug 18 '13 at 14:45