2

The code below used to work nicely in 11.0:

ϕc[x_, y_, α_] = r^(Pi/α) Cos[Pi/α θ] /. {r -> Sqrt[x^2 + y^2], θ -> ArcTan[x, y]};
StreamPlot[
  {D[ϕc[x, y, α], x], D[ϕc[x, y, α], y]} /. α -> Pi/2, {x, 0.001, 3}, {y, 0.001, 3}]

but in 11.1 the functions in StreamPlot get the values of x and y substituted in before the derivative is evaluated, with consequent General::ivar: 0.0012142143 is not a valid variable errors. I can do something like

ϕc[x_, y_, α_] = r^(Pi/α) Cos[Pi/α θ] /. {r -> Sqrt[x^2 + y^2], θ -> ArcTan[x, y]};
f = D[ϕc[x, y, α], x] /. α -> Pi/2;
g = D[ϕc[x, y, α], y] /. α -> Pi/2;
StreamPlot[{f, g}, {x, 0.001, 3}, {y, 0.001, 3}]

Of course, but that's kind of clunky. Long story short, I think my question is how do I create "inline definitions" of the kind of functions I have in the example above?

P.S.: And why in all the world does Wolfram introduce substantial changes like that in a minor version update, or at all?

Alexey Popkov
  • 61,809
  • 7
  • 149
  • 368
Pirx
  • 4,139
  • 12
  • 37

1 Answers1

2

As Carl Woll suggests in the comments, you should use the option Evaluated->True to reproduce the version 11.0 behavior, or wrap the first argument in Evaluate:

StreamPlot[
  {D[ϕc[x, y, α], x], D[ϕc[x, y, α], y]} /. α -> Pi/2, {x, 0.001, 3}, {y, 0.001, 3}, 
  Evaluated -> True]

plot

StreamPlot[Evaluate[{D[ϕc[x, y, α], x], D[ϕc[x, y, α], y]} /. α -> Pi/2],
  {x, 0.001, 3}, {y, 0.001, 3}]

(output is the same).

The first method is recommended because Evaluated->True localizes the variables during symbolic evaluation, as opposed to wrapping the first argument by Evaluate.

Alexey Popkov
  • 61,809
  • 7
  • 149
  • 368