0
$\begingroup$

The minimum of $f(x) = -(x+1/2 \sqrt{1-x})$ for $x$ between $0$ and $1$ occurs at $x=15/16$ with $f(15/16)=-17/16$. This is a function that Mathematica evaluates quickly, and I have plotted the function and its minimum values below:

Mathematica plot of function f

Mathematica quickly evaluates

Minimize[{-x - 1/2 Sqrt[1 - x] , x > 0, x < 1}, x]

but is extremely slow in evaluating

NMinimize[{-x - 1/2 Sqrt[1 - x] , x > 0, x < 1}, x]

(In fact, Mathematica appears to hang when I try to evaluate the above.)

Why is this and how can I speed up the evaluation? Is it the way I specified the bounds? I have in mind somewhat more complicated examples but I'm hoping to understand this simple example first. I'm running 12.0 Student Edition on Windows 10.

$\endgroup$
2
  • 4
    $\begingroup$ On my installation (MM 12.1 on MacOS), both commands run effectively instantaneously, with the latter returning {-1.0625, {x -> 0.9375}} as expected. So this may be a version-dependent bug. $\endgroup$ Sep 16, 2021 at 20:27
  • $\begingroup$ Try this comparison on a fresh kernel. $\endgroup$
    – user64494
    Sep 17, 2021 at 18:43

1 Answer 1

1
$\begingroup$

The Method->"DifferentialEvolution" option helps: compare

Minimize[{-x - 1/2 Sqrt[1 - x], x > 0, x < 1}, x] // AbsoluteTiming

{0.287915, {-(17/16), {x -> 15/16}}}

with

NMinimize[{-x - 1/2 Sqrt[1 - x], x > 0, x < 1}, x, 
Method -> "DifferentialEvolution"] // AbsoluteTiming

{0.116188, {-1.0625, {x -> 0.9375}}}

and with

NMinimize[{-x - 1/2 Sqrt[1 - x], x > 0, x < 1}, x] // AbsoluteTiming

0.298761, {-1.0625, {x -> 0.9375}}}

$\endgroup$
2
  • $\begingroup$ The above is done in 12.3.1 on Windows 10. Though the NMinimize command was updated in 12.3, but its parts related to Methods weren't up to the documentation. $\endgroup$
    – user64494
    Sep 17, 2021 at 18:58
  • $\begingroup$ The difference is night and day on my installation - it finishes running when implementing the method you recommended, so this solves my problem. $\endgroup$
    – user196574
    Sep 17, 2021 at 20:23

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.