# Evaluating Functions on Zero Sets (of other functions)

I have a highly non-trivial function, call it $f(x,y)$, in which I want to look at its zero set in the $(x,y)$ plane, and plot/evaluate a different function $g$ precisely along this zero set. I have a nice way of doing this when the zero set of $f$ can be parameterized by $x$, i.e. $y(x)$, but in general, this zero set will not be nicely parameterized by $x$.

Is there a nice way to parameterize zero sets by some parameter $t$, like length along the curve, and then save values and plot $g(x(t),y(t))$? Perhaps it might be helpful to take an easy example like

f[x_,y_]=x^2+y^2-4 g[x_,y_]=x^2-3*y^2

Unlike the case of the circle above, my zero set certainly does not have a nice, obvious parameterization, so instead perhaps someone can help me form a numerical recipe using the simple example above.

**If it helps, I can upload the case I actually have in mind, but it's rather messy and requires a lot of pre-amble.

Plot3D[g[x, y], {x, -5, 5}, {y, -5, 5}, MeshFunctions -> {f[#, #2] &},
Mesh -> {{{0, Directive[Thick, Red]}}}, BoxRatios->1]


Plot3D[g[x, y], {x, -5, 5}, {y, -5, 5}, PlotStyle -> None,
BoundaryStyle -> None, MeshFunctions -> {f[#, #2] &},
Mesh -> {{{0, Directive[Thick, Red]}}}, BoxRatios->1]


cp = ContourPlot[f[x, y] == 0, {x, -5, 5}, {y, -5, 5},  ContourStyle -> {Thick, Red}]


Graphics3D[cp[[1]] /. GraphicsComplex[coords_, rest___] :>
GraphicsComplex[{##, g[##]} & @@@ coords, rest],
BoxRatios -> 1,  Axes -> True]


• Thanks a lot for this. Perfect visualization of what I'm after. The main thing I was after is a parameterization of the zero set such that I can save values of $g$ evaluated as a function of this parameter. Is there a way to do this using the above, or is it simply a plotting technique? – Benighted May 10 '16 at 0:57
• @spietro, you can use the second example above as plot = Plot3D[...] to extract the coordinates using coords = Cases[Normal[plot], Line[x_] :> x, Infinity][[1]]. In each triple in this list, the first two coordinates satisfy f[x,y]==0 and the third coordinate is g[x,y]. – kglr May 10 '16 at 1:16
• Wow, that works perfectly and is precisely what I was hoping for; thanks! Is there a way to vary the number of triples we output in coords? Don't see a parameter that would control this. – Benighted May 10 '16 at 1:46
• @spietro, you can play with PlotPoints and MaxRecursion in Plot3D to change the number of points in coords-- but I don't know the exact mapping between the number of points in coords the values of these two options. – kglr May 10 '16 at 1:53

Can use NDSolve to parametrize numerically.

f[x_, y_] = x^2 + y^2 - 4;
g[x_, y_] = x^2 - 3*y^2;
pt = {2, 0};

xyvals = NDSolveValue[
Flatten[{D[f[x[t], y[t]], t] == 0, x'[t]^2 + y'[t]^2 == 1,
Thread[{x[0], y[0]} == pt]}], {x[t], y[t]}, {t, 0, 11}];


(If you want to see the better part of a circle, do ParametricPlot[xyvals, {t, 0, 11}, AspectRatio -> 1])

Now to plot g on this set, do:

Plot[g @@ xyvals, {t, 0, 11}]


• Thanks! So it looks like xyvals is such that I can input some $t$ in the chosen range and output the corresponding $(x,y)$. So it should be straightforward to choose discrete points in xyvals and save the associated $g(x(t),y(t))$? – Benighted May 10 '16 at 2:36
• Yes, that's exactly right. – Daniel Lichtblau May 10 '16 at 14:45
• So I've been playing with this code, and tried to apply it to cases where the zero set has more that one "component." For example f[x_, y_] = (x^2 + y^2 - 4) ((x - 1)^2 + y^2 - 4). The resulting plot for xyvals picks up half of one circle, and half of the other. Perhaps if the zero set has multiple disjoint components, you can parameterize just one component by choosing the initial point properly? Can't seem to get that to work nicely. – Benighted May 11 '16 at 2:36
• (1) I'm really surprised that NDSolve jumped paths at a nontangential intersection. Anyway, as you note, multiple components and self intersections are both troublesome for the method, and so I should have stated it is really only local in nature. I do not know of a global approach. Best I can suggest is what you already know: use multiple initial points... – Daniel Lichtblau May 11 '16 at 13:49
• (3) There might be something of use in this recent Wolfram Technology Conference presentation. And the author is working on expanding all this into an e-book. – Daniel Lichtblau May 11 '16 at 13:57