5
$\begingroup$

Is there a way in Mathematica to determine a parametric equation of a level curve in Mathematica. For example, consider:

f[x_, y_] = (x^2 + 3 y^2) Exp[-x^2 - y^2]; Plot3D[
 f[x, y], {x, -1, 1}, {y, -2, 0},
 MeshFunctions -> {#3 &},
 Mesh -> {{0.7}}]

Any way to find a parametrization of the level curve f[x,y] = 7/10 ?

$\endgroup$
  • $\begingroup$ Maple produces $$\small \begin{cases} x&={\frac1{t^2+1}\sqrt {-\left(t^2+1\right) {\rm W} \left(-{\frac {7\,t^2+7}{30\,t^2+10}}\right)}}\\ y &= {\frac{t}{t^2+1}\sqrt {- \left(t^2+1 \right) {\rm W} \left(-{\frac {7\,t^2+7}{30\,t^2+10}}\right)}} \end{cases}$$ and $$\small \begin{cases}x&=-{\frac {1}{{t}^{2}+1}\sqrt {- \left( {t}^{2}+1\right) {\rm W} \left(-{\frac {7\,{t}^{2}+7}{30\,{t}^{2}+10}}\right)}}\\ y &= -{\frac {t}{{t}^{2}+1}\sqrt {- \left( {t}^{2}+1 \right) {\rm W} \left(-{\frac {7\,{t}^{2}+7}{30\,{t}^{2}+10}}\right)}}\end{cases},$$ where $W$ is the Lambert function. $\endgroup$ – user64494 Jul 22 '15 at 4:06
  • $\begingroup$ Transcendental functions tend to be a bit difficult to parametrize analytically. If need be, you can always build an InterpolatingFunction[]. $\endgroup$ – J. M.'s technical difficulties Jul 22 '15 at 4:20
  • $\begingroup$ The verification shows that the above formulas produce only a part of the level set. $\endgroup$ – user64494 Jul 22 '15 at 4:53
  • $\begingroup$ @user, apart from switching the signs of the square roots, try the "-1" branch of the Lambert function, $W_{-1}(z)$. $\endgroup$ – J. M.'s technical difficulties Jul 22 '15 at 4:58
  • $\begingroup$ I believe you should de-accept my solution for now. I think that there is a way to get a closed-form parameterization by adapting @MarcoB's solution. $\endgroup$ – march Jul 22 '15 at 16:12
5
$\begingroup$

Update. The argument about not getting a nice closed form is of course wrong. (The $W$ Lambert function is nicer than I expected and is implemented in Mathematica as ProductLog.) Nonetheless, I think that the numerical solution below is useful, so I will leave this solution up.

Original post

As stated by Guess who it is in a comment and shown by user64494's functions that are in terms of the transcendental function W, you cannot get a nice closed form for the parameterization. A simple way to see this is to note that one way to get the parameterization is to solve 0.7 == f[x, y] for y yielding some function y[x], in which case the parameterization would be {x, y[x]}. Unfortunately, the equation

0.7 == (x^2 + 3 y^2) Exp[-x^2 - y^2]

is a transcendental equation and can't be solved.

So let's take a numerical approach, hinted at by Guess who it is in a comment. We first extract the data points from the plot. Using

f[x_, y_] = (x^2 + 3 y^2) Exp[-x^2 - y^2];
plot = Plot3D[f[x, y]
  , {x, -1, 1}, {y, -2, 0}
  , MeshFunctions -> {#3 &}
  , Mesh -> {{0.7}}
  , BoundaryStyle -> None]

we can extract the curve as a sequence of points using

points = Cases[Normal@plot, Line[a_] :> a, Infinity];

Using BoundaryStyle -> None guarantees that the only Line in the plot is the contour of interest. This yields a set of {x, y} coordinates for the curve.

We artificially introduce a parameterization variable t that takes the value 0 for the first point, 1 for the second point, and so on, so that t ranges from 0 to Length@points - 1. We create two lists, one for {t, x[t]} and one for {t, y[t]} via

xyLists = Transpose@MapIndexed[{{#2[[1]] - 1, #1[[1]]}, {#2[[1]] - 1, #1[[2]]}} &, points]

From these, we create InterpolatingFunctions via

interps = Interpolation[#][t] & /@ xyLists

resulting in a list of two InterpolatingFunctions. We create our parameterized function as

curve[t_] = Join[interps, {0.7}];

Finally, we can plot this:

Show[
  Plot3D[
    f[x, y]
    , {x, -1, 1}, {y, -2, 0}
    , Mesh -> None
    , ViewPoint -> {1.5, -1.5, 2.5}
  ]
  , ParametricPlot3D[
     curve[t]
     , {t, 0, Length@points - 1}
    ]
 ]

which results in the following plot:

enter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ I just wanted to point out that Reduce will in fact give you explicit solutions for that equation, which is what I used in my answer. Interesting approach nonetheless. $\endgroup$ – MarcoB Jul 22 '15 at 6:27
  • $\begingroup$ The first comment demonstrates that the equation is solvable in terms of the Lambert function; it just happens to look messy for this case. $\endgroup$ – J. M.'s technical difficulties Jul 22 '15 at 6:42
  • $\begingroup$ @Guesswhoitis. Yeah, apparently I didn't read enough about $W$. Apparently it's the same as ProductLog (as shown in MarcoB's solution). I'm going to encourage the OP to unaccept, because I'm pretty sure MarcoB's solution can be adapted for what the OP wants. $\endgroup$ – march Jul 22 '15 at 16:10
  • $\begingroup$ @march Definitely do not delete what you have done. It is awesome and opens a huge window for learning. Great job! $\endgroup$ – David Jul 22 '15 at 17:53
3
$\begingroup$

Not exactly a parametrization, but I wonder if this might help:

Clear[contourplot]
contourplot[level_] := Module[
  {},
  solns = Reduce[(x^2 + 3 y^2) Exp[-x^2 - y^2] == level, {x, y}, Reals];
  Show[

   Plot3D[(x^2 + 3 y^2) Exp[-x^2 - y^2], {x, -2, 2}, {y, -2, 2}, Mesh -> None],

   ParametricPlot3D[
    Tooltip[Evaluate[{x, #, level} & /@ (y /. {ToRules[solns[[2]]]})], N@level],
    {x, -1, 1},
    PlotStyle -> Directive[Red, Thick]
   ],

   ImageSize -> Scaled[1/4]
   ]
  ]

Multicolumn[contourplot[#/10] & /@ Range[7, 11], 3, Appearance -> "Horizontal"]

Mathematica graphics

I have to warn you, though, that Reduce will refuse to collaborate for some level values. I haven't explored numerical solutions because I think they might not be what you are after, but that option may be available as well.

| improve this answer | |
$\endgroup$
  • $\begingroup$ This is not a parametrization at all. $\endgroup$ – user64494 Jul 22 '15 at 5:00
  • 1
    $\begingroup$ @user64494 Yes, well, that's why the post starts with "Not exactly a parametrization, but..." :-) $\endgroup$ – MarcoB Jul 22 '15 at 5:03
  • 1
    $\begingroup$ @user64494. I believe this can be adapted and turned into a parameterization, however... $\endgroup$ – march Jul 22 '15 at 16:10
  • $\begingroup$ @MarcoB Just a wonderful response. I have so much to learn and this is extremely helpful. I look forward to any updates. $\endgroup$ – David Jul 22 '15 at 17:54

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.