4
$\begingroup$

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?

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

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:

sol=Refine[sol,{11>x>-11}];

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.)

dsol=D[sol[[2]],x]

differentiate function

Now we can search for solutions:

xsol=x/.Solve[dsol==0,x,Reals]

{{x->-11.1445},{x->-7.17004},{x->-3.16044},{x->0},{x->3.16044},{x->7.17004},{x->11.1445}}

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

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

solutionpoints=({#,sol[[2]]/.x->#})&/@xsol

{{-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:

Show[Plot[sol,{x,-10,10}],ListPlot[solutionpoints]]

solutionpoints

EDIT: NMaximize would have also worked:

NMaximize[{z,f==E0,0<x<5},{x,z}]

{2.61846,{x->3.16044,z->2.61846}}

Which is the same solution.

| improve this answer | |
$\endgroup$

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.