2

I would like to define a function using variables outside of the function.

For example,

g = x + y;
f[x_, y_] := g;
f[1, 2]

then, I hope to get 3 as the answer. In above case, I get

x + y

as the answer.

  • 3
    Just change SetDelayed := sign by equal = – robson denke Jun 28 '17 at 14:21
  • Further reading: https://mathematica.stackexchange.com/questions/8829/what-is-the-difference-between-set-and-setdelayed – yohbs Jun 28 '17 at 14:25
  • Possible duplicate: (69590) -- if you expect to redefine g and have it affect f you will need that. If g is defined before f only then Set (shorthand =) is sufficient. Would you please clarify your intent? – Mr.Wizard Jun 28 '17 at 14:32

0 Answers0