2

I am working on Wagon's FindRoots2D section.

Clear[f];
f[x_, y_] := x - y^2 Cos[y];
g[x_, y_] := -y + x Sin[x];
fcnVec[{x_, y_}] := {f[x, y], g[x, y]};

I am starting (still a rookie) to understand that one can get the data of any object in Mathematica. For example, a contour plot.

cp = ContourPlot[f[x, y] == 0, {x, -10, 10}, {y, -10, 10}]

enter image description here

I've learned that if I look at FullForm[cp], I'll see that the data is using the GraphicsComplex idea, which I have a beginner's understanding of. If I look at FullForm[Normal[cp]], then I see the Line command using the actual data points instead of indices to the GraphicsComplex data. Now, Stan Wagon uses the Cases command to get those points. I try:

Cases[Normal[cp], Line[z_] :> z]

And I get an empty set. Then I try Stan's:

Cases[Normal[cp], Line[z_] :> z, ∞]

And I get all of the points. This is where I am stuck. Why does the Infinity symbol make a difference here?

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
David
  • 14,883
  • 4
  • 44
  • 117

1 Answers1

6

The explanation is readily found in the documentation of Cases.

  • Cases uses standard level specifications
  • The default value for levelspec in Cases is {1}

The Line expressions are not at level 1, and in fact may be at more than one level. Using ∞ as the level spec tells Cases to look at all levels.

m_goldberg
  • 107,779
  • 16
  • 103
  • 257