# Define Function using another Function and plot

I have a function defined by

f[x_, y_] := 1/(x^2+1) + 1/(y^2+1);

I can plot this function perfectly.

Then I want to StreamPlot the gradient of that function so I do:

myGrad[x_, y_] = Grad[f[x, y], {x, y}]]

(I also tried some different approaches with := and Evaluate and Function here.)

Sadly

StreamPlot[myGrad[x, y], {x, -2, 5}, {y, -2, 5}]

produces a blank plot. On the other hand, using the output as %xyz from the myGrad definition as the 1st argument in the StreamPlot call, renders a plot.

So, how do I reuse a functions result as definition of a new function and use the new function in a plot?

• On my machine "11.3.0 for Mac OS X x86 (64-bit) (March 7, 2018)" your code produces a plot, no problem. – Roman Feb 11 '19 at 21:58

## 1 Answer

ClearAll[f, myGrad]
f[x_, y_] := 1/(x^2 + 1) + 1/(y^2 + 1);
myGrad[x_, y_] := Grad[f[x, y], {x, y}];


Use the option Evaluated -> True or wrap the first argument with Evaluate in StreamPlot:

StreamPlot[myGrad[x, y], {x, -2, 5}, {y, -2, 5}, Evaluated -> True] StreamPlot[Evaluate @ myGrad[x, y], {x, -2, 5}, {y, -2, 5}]


same picture

• Thanks, that does the trick! – Julian Strecker Feb 12 '19 at 16:03