A simple implicit function

f = -0.000462963 x^2 - 0.1/Sqrt[0.0625 + (-3. + x)^2 + z^2]
    - 0.1/Sqrt[0.0625 + (3. + x)^2 + z^2];
E0 = -0.0575;

and the corresponding contour plot

C0 = ContourPlot[f == E0, {x, -12, 12}, {z, -12, 12}, 
     ContourStyle -> {{Black, Thickness[0.004]}}, AspectRatio -> 1, 
     ContourShading -> False, PlotPoints -> 100, 
     PerformanceGoal -> "Quality"]

enter image description here

My target is to numerically obtain the maximum value of $z$ in the interval $-6 < x < 6$.

However when I use

max = NMaximize[{x, f == E0}, {{x, -6, 6}, z}];

the program compute a maximum value outside the desired interval. Why? Am I doing something wrong?

  • $\begingroup$ What is Vxz in you Contourplot? $\endgroup$ Sep 28, 2016 at 14:10
  • $\begingroup$ @JulienKluge It's an error. See my edit. $\endgroup$
    – Vaggelis_Z
    Sep 28, 2016 at 14:12
  • $\begingroup$ I think you mean E0 = - 0.0575 as well. $\endgroup$ Sep 28, 2016 at 14:23
  • $\begingroup$ @MariusLadegårdMeyer You are right! $\endgroup$
    – Vaggelis_Z
    Sep 28, 2016 at 14:26

1 Answer 1


It was not nessecary to do it numerically. Solve with assumptions works.

Lets assume $x$ and $z$ to be $x,z\in\mathbb{R}$ and solving this:

sol = z /. Solve[f == E0, z, Reals];

This gives two solutions with a condition that $-11.1445 < x < 11.1445$. So we refine:


Lets differentiate it and take only the first or second function. (The second funtion is the one you want but both are symmetrical so it does not matter.)


differentiate function

Now we can search for solutions:



So we see that $x\approx\pm 3.16044$ is your solution.

To get all pairs of solutions $(x,z)$ we map accordingly


{{-11.1445,316.044},{-7.17004,0.305369},{-3.16044,2.61846},{0,0. +3.0104 I},{3.16044,2.61846},{7.17004,0.305369},{11.1445,316.044}}

which gives you your two solutions to be: $$(x_{1,2},z_{1,2})=(\pm3.16044,2.61846)$$ and displaying the result:



EDIT: NMaximize would have also worked:



Which is the same solution.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.