When I want to StreamPlot[myGradient[x,y], {x, -2, 2}, {y, -2, 2}] I got an empty diagram. When I use the output of the second last command (myGradient…) the Plotting works fine (StreamPlot[%6, {x, -2, 2}, {y, -2, 2}]).
Why does it not work like this and how do I do it right? In general I want to use the output of some input as the value of a function.
That graph will display, but might look a little odd, changing your function to x^2 - y^4 might give a StreamPlot that looks more reasonable.
What the differences are between := and = and exactly why the evaluation does what it does in your example is a deeper issue. Understanding the depths of how evaluation works in Mathematica is key.
You also need to be aware of any cached prior definitions of functions which can sometimes change the behavior that you might be expecting. Those might be responsible for some of the problems you are seeing. You can quit the kernel or clear individual definitions or restart Mathematica to eliminate those.
The documentation for StreamPlot shows that StreamPlot is expecting a vector as its argument. The “Details and options” lists show three statements that apply.
StreamPlot does not show streamlines at any positions for which the Subscript[v, i] etc. do not evaluate to real numbers.
StreamPlot has attribute HoldAll, and evaluates the Subscript[v, i] etc. only after assigning specific numerical values to x and y.
In some cases it may be more efficient to use Evaluate to evaluate the Subscript[v, i] etc. symbolically before specific numerical values are assigned to x and y.
With these in mind the command to ensure a plot follows.