4
$\begingroup$

Consider:

f = 0.5 (x^2 + y^3); ContourPlot[f, {x, -1, 1}, {y, -1, 1}, MeshFunctions -> {Function[{x, y, z}, x], Function[{x, y, z}, 3 y^2/2]}, Mesh -> {{0}, {0}}, MeshStyle -> {Directive[Thick, Yellow], Directive[Red, Thick, Dashed]}] 

Which produces this image.

enter image description here

Why doesn't the Red, Thick, Dashed mesh show up?

Example showing why it will not just be lines:

f[x_, y_] = x^2 - 4 x y/(y^2 + 1); ContourPlot[f[x, y], {x, -2, 2}, {y, -2, 2}, MeshFunctions -> {Function[{x, y, z}, Evaluate@D[f[x, y], x]], Function[{x, y, z}, Evaluate@D[f[x, y], y]]}, Mesh -> {{0}, {0}}, MeshStyle -> {Directive[Thick, Dashed, Red], Directive[Thick, Yellow]}] 

Which produces:

enter image description here

$\endgroup$
3

1 Answer 1

5
$\begingroup$

You are looking at the zero of the function $y^2/2$, which is a zero of order 2. This makes it hard for the numeric function to find this. Play a little with the value, and you get the desired result.

f = 0.5 (x^2 + y^3); ContourPlot[f, {x, -1, 1}, {y, -1, 1}, MeshFunctions -> {Function[{x, y, z}, x], Function[{x, y, z}, 3 y^2/2]}, Mesh -> {{0}, {10^-7}}, MeshStyle -> {Directive[Thick, Yellow], Directive[Red, Thick, Dashed]}] 

enter image description here

$\endgroup$
4
  • 1
    $\begingroup$ BTW, wouldn't it be easier drawing these lines with Epilog? $\endgroup$ Commented Jul 8, 2015 at 19:45
  • $\begingroup$ Wow! Nice answer. Thanks for the help. $\endgroup$ Commented Jul 8, 2015 at 19:45
  • 4
    $\begingroup$ @David, since you're teaching calculus, think of it this way: ContourPlot[] relies on the intermediate value theorem; if it can't find any sign changes in the function values along a putative contour, then it won't draw the contour. So, if your surface merely touches the $x$-$y$ plane as opposed to crossing it, you'll have a hard time visualizing the contour at $z=0$. $\endgroup$ Commented Jul 8, 2015 at 23:03
  • $\begingroup$ @yohbs: Yes, I could have used Epilog. But they won't always be lines. I've added an example to my original post explaining why. This is going to be visually helpful to students when they are trying to determine critical values for optimization. $\endgroup$ Commented Jul 9, 2015 at 0:57

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.