2
$\begingroup$

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?

$\endgroup$
  • 1
    $\begingroup$ Try StreamPlot[{Derivative[1, 0, 0][ϕc][x, y, π/2], Derivative[0, 1, 0][ϕc][x, y, π/2]}, {x, 0.001, 3}, {y, 0.001, 3}]. $\endgroup$ – J. M.'s discontentment Oct 31 '17 at 20:35
  • 2
    $\begingroup$ Use the option Evaluated->True to obtain the M11.0 behavior, or wrap the first argument in Evaluate. $\endgroup$ – Carl Woll Oct 31 '17 at 20:37
2
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.