# Evaluating function before its plotting

Suppose I want to plot a function $$f(x,y)$$ but first need to calculate its symbolic expression. An easy solution is to copy the output of my calculation by hand and then paste into Plot function. If I naively do this

f[x_,y_]:= 100*x^3+Tanh[y^2];
Plot3D[f[x,y],{x,-10,10},{y, -20, 20}]


then it runs very slowly (for a much more complicated function I'm plotting). I think what's happenning is that instead of symbolically calcualte f[x,y], Mathematica numerically calculates it.

Question: is there a way to delay Plot first and evaluate the function inside Plot? Maybe using Hold? But I don't see how I can evaluate the function first after holding.

• Use f[x_,y_] = 100*x^3+Tanh[y^2] instead of f[x_,y_] := 100*x^3+Tanh[y^2]? Either that, or make a Table of values instead and use ListPlot3D. – march Jun 9 '19 at 14:27
• Expanding on what @march said: please read up on the distinction between immediate and delayed definitions. If you don't want to delay the definition, then just don't use a delayed definition (i.e., use an immediate definition instead). – Roman Jun 9 '19 at 15:59
• Add the option Evaluated->True inside Plot3D – Ulrich Neumann Jun 9 '19 at 18:52

Plot3D has attribute HoldAll, so its arguments are not evaluated before variable substitution. You can override this with:
Plot3D[Evaluate[f[x, y]], {x, -10, 10}, {y, -20, 20}]