4
$\begingroup$

I ran into some weird errors when using NSolve inside ColorFunction. Took some hours to distill the problem into a minimal example:

Plot[-x, {x, -1, 1}, ColorFunction -> (Hue[n1 /. NSolve[{
  0 == n1 (1 - #1^2 - n1 - E^(-2 (#1 - #2)^2) n2),
  0 == (1 - #2^2 - E^(-2 (-#1 + #2)^2) n1 - n2) n2}, {n1, n2}][[1]]] &)]

Break::nofwd: No enclosing For, While, or Do found for Break[]. (X3)

Continue::nofwd: No enclosing For, While, or Do found for Continue[].

Goto::nolabel: Label System``NSolveDump` raiseprecision not found. (etc.)

Hold[Break[], Break[], Break[], Continue[],
  Goto[System`NSolveDump`raiseprecision], Continue[], Break[], Continue[]]

Seems related to this question, but potentially more confusing since no Break is apparently involved.

I'm using Mathematica v11.2 on MacOS 10.13.3.

$\endgroup$
  • 1
    $\begingroup$ Looks like a bug, though. Probably the same one, but one can't say for sure without seeing the internals. $\endgroup$ – Michael E2 Feb 25 '18 at 16:18
  • 1
    $\begingroup$ Since this was identified as a bug in 2012 and is still not fixed, I am tagging this question with bugs. $\endgroup$ – m_goldberg Feb 25 '18 at 17:27
  • $\begingroup$ Thanks, I'll report it to WRI. $\endgroup$ – Chris K Feb 25 '18 at 17:39
3
$\begingroup$

One solution proposed in the same previous question works here: wrap the ColorFunction in an Unevaluated.

Plot[-x, {x, -1, 1}, ColorFunction -> (Unevaluated[Hue[n1 /. NSolve[{
  0 == n1 (1 - #1^2 - n1 - E^(-2 (#1 - #2)^2) n2),
  0 == (1 - #2^2 - E^(-2 (-#1 + #2)^2) n1 - n2) n2}, {n1, n2}][[1]]]] &)]

Mathematica graphics

$\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.