4
$\begingroup$
Solve[ Sqrt[Abs[x]^2+Abs[-5+y]^2]+Sqrt[Abs[-5+x]^2+Abs[y]^2]
      +Sqrt[Abs[5+x]^2+Abs[y]^2]+Sqrt[Abs[x]^2+Abs[5+y]^2]==24 &&
      -6 < x < 6, y]  

When I evaluated this expression, after almost 30 minutes I've got nothing.
I am not sure whether that's because my Intel i7 CPU, I guess it's strong enough.

How can I solve this equation?

How can I know the calculation time? I'd quit if needed more than 1 hour.

$\endgroup$
0

2 Answers 2

6
$\begingroup$

In general you can't know in advance how long you should wait for solutions (even you won't know if the system is capable to provide them at all). There is TimeConstrained[expr, constr] to stop computation of expr when it exceeds the time constraint constr.

Nonetheless Solve works fine (Reduce even finer, this is a huge issue, see e.g. this post) and it is capable to provide solutions quickly if you supplement the system to be solved with appropriate restriction on variables. To realize what kind of restrictions you should add to solvers I'd recommend to examine thoroughly this post How to get intersection values from a parametric graph? Having used ContourPlot you should easily figure out them. So we can get solutions

sols = y /. 
Solve[ Sqrt[ Abs[x]^2 + Abs[-5 + y]^2] + Sqrt[Abs[-5 + x]^2 + Abs[y]^2] + 
     Sqrt[Abs[5 + x]^2 + Abs[y]^2] + Sqrt[Abs[x]^2 + Abs[5 + y]^2] == 24 &&
    -6 < x < 6 && -6 < y < 6, y];

Solutions are represented in terms of the Root objects, sometimes they can be rewritten in terms of radicals (see e.g. this post)

Now, we can plot the solutions:

Plot[ sols, {x, -2 Sqrt[6], 2 Sqrt[6]}, 
      AspectRatio -> Automatic, PlotStyle -> Thick]

enter image description here

To realize what you might expect if you assume that y is complex, it is advantageous to exploit ContourPlot. I write y as z == k I + y, that is y is the real part of z, e.g. :

With[{k = 1.316}, 
  ContourPlot[ Sqrt[Abs[x]^2 + Abs[-5 + k I + y]^2] + Sqrt[Abs[-5 + x]^2 + Abs[k I + y]^2]
              + Sqrt[Abs[5 + x]^2 + Abs[k I + y]^2] + Sqrt[Abs[x]^2
              + Abs[5 + k I + y]^2] == 24,
              {x, -6, 6}, {y, -6, 6},
              AspectRatio -> Automatic]]

To get a bit deeper insight we'll look at the animation.

soly = 
  Table[ ContourPlot[ Sqrt[Abs[x]^2 + Abs[-5 + k I + y]^2] + Sqrt[Abs[-5 + x]^2 
                      + Abs[k I + y]^2] + Sqrt[Abs[5 + x]^2 + Abs[k I + y]^2] 
                      + Sqrt[Abs[x]^2 + Abs[5 + k I + y]^2] == 24,
                     {x, -5, 5}, {y, -5, 5},
          PlotLegends -> Placed[ Style[Row[{"k =", NumberForm[k, {4, 2}]}], Bold, 20],
                                {Left, Top}], ContourStyle -> Thick],
         {k, -3.316, 3.316, 0.04}];

ListAnimate[ soly, Paneled -> False]

enter image description here

$\endgroup$
1
  • $\begingroup$ Having looked at the ContourPlot the exact bounds can be found from Solve[Sqrt[Abs[x]^2 + Abs[-5 + y]^2] + Sqrt[Abs[-5 + x]^2 + Abs[y]^2] + Sqrt[Abs[5 + x]^2 + Abs[y]^2] + Sqrt[Abs[x]^2 + Abs[5 + y]^2] == 24 /. #[[1]], #[[2]]] & /@ {{y -> 0, x}, {x -> 0, y}} $\endgroup$
    – Bob Hanlon
    Commented Mar 26, 2018 at 16:24
3
$\begingroup$

y is a real number, right? Then

eqn = Sqrt[Abs[x]^2 + Abs[-5 + y]^2] + Sqrt[Abs[-5 + x]^2 + Abs[y]^2] + 
     Sqrt[Abs[5 + x]^2 + Abs[y]^2] + Sqrt[Abs[x]^2 + Abs[5 + y]^2] == 24 && -6 < x < 6;

(* Solution 1 *)
sol = Solve[eqn /. Abs -> RealAbs, y]; // AbsoluteTiming
(* {1.37403, Null} *)
(* Solution 2 *)
sol2 = Solve[eqn, y, Reals]; // AbsoluteTiming
(* {1.44141, Null} *)
$\endgroup$
3
  • $\begingroup$ y should be expression, not a number $\endgroup$
    – kittygirl
    Commented Mar 26, 2018 at 13:56
  • 2
    $\begingroup$ @kittygirl A preciser statement is "y is an expression that evaluates to a real number for any desirable x" of course. $\endgroup$
    – xzczd
    Commented Mar 26, 2018 at 14:11
  • $\begingroup$ +1 for bringing up RealAbs. I didn't know that and I was positively surprised that RealAbs' evaluates to somethin reasonable (although I am a bit disappointed by `RealAbs''). $\endgroup$ Commented May 1, 2018 at 11:00

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.