2
$\begingroup$

I want to find min of the function $$\frac{1}{\sqrt{2 x^2+\left(3+\sqrt{3}\right) x+3}}+\frac{1}{\sqrt{2 x^2+\left(3-\sqrt{3}\right) x+3}}+\sqrt{\frac{1}{3} \left(2 x^2+2 x+1\right)}.$$ I know, the exact value minimum is $\sqrt{3}$ at $x = 0$. With Mathematica, I tried

A = 1/Sqrt[2 x^2 + (3 + Sqrt[3]) x + 3] + 
  1/Sqrt[2 x^2 + (3 - Sqrt[3]) x + 3] + Sqrt[(2 x^2 + 2 x + 1)/3]
NMinimize[A, {x}]

And I got

{1.73205, {x -> -2.57345*10^-16}}

When I tried

A = 1/Sqrt[2 x^2 + (3 + Sqrt[3]) x + 3] + 
  1/Sqrt[2 x^2 + (3 - Sqrt[3]) x + 3] + Sqrt[(2 x^2 + 2 x + 1)/3]
Minimize[A, {x}]

my computer ran about 20 minutes and I did not got the result. How can I get the exact value minimum of the given function?

$\endgroup$
7
$\begingroup$

In this case you can find minimum by comparing values at zero derivates:

TakeSmallestBy[{A /. #, #} & /@ Solve[D[A, x] == 0, x, Reals], First, 1]

{{Sqrt[3], {x -> 0}}}

TakeSmallestBy is a v10.1 function similar to MinimalBy, but performs numerical comparisons.

$\endgroup$
5
  • $\begingroup$ Or First@MinimalBy[First][{A /. #, #} & /@ Solve[D[A, x] == 0, x, Reals]] for 10.0.x users. $\endgroup$ – Taiki Apr 3 '15 at 10:03
  • $\begingroup$ @Taiki The problem with MinimalBy is that it doesn't perform the comparison numerical order, but instead by using OrderedQ ordering. Of course there are correct ways to do this in pre-v10.1 versions too, but they're a bit awkward (Sorting with Less as comparison function, or such)... $\endgroup$ – kirma Apr 3 '15 at 10:09
  • $\begingroup$ I can't see why it's a problem here. The canonical order of First[e_i] is by numerical magnitude anyway. $\endgroup$ – Taiki Apr 3 '15 at 10:23
  • $\begingroup$ @Taiki Order given by MinimalBy is correct by sheer luck in this case. Consider MinimalBy[x /. Solve[D[A, x] == 0, x, Reals], Identity, 3] // N (* {0., -2.14393, -1.20441} *) - from this its' obvious you can't trust MinimalBy to give numerically sorted ordering of symbolic expressions. $\endgroup$ – kirma Apr 3 '15 at 10:29
  • 1
    $\begingroup$ Oh right... you meant that MinimalBy wouldn't evaluate Root? Yeah the result is indeed correct by luck here. $\endgroup$ – Taiki Apr 3 '15 at 10:32
0
$\begingroup$
a[x_] := Sqrt[1 + 2 x + 2 x^2]/Sqrt[3] + 1/Sqrt[
  3 + (3 - Sqrt[3]) x + 2 x^2] + 1/Sqrt[3 + (3 + Sqrt[3]) x + 2 x^2]

Plot[a[x], {x, -5, 5}]

enter image description here

extr = NSolve[a'[x] == 0, x, Reals]

{{x -> -2.14393}, {x -> -1.20438}, {x -> 0.}}

{a[x] /. #, #} & /@ extr

{{2.42668, {x -> -2.14393}}, {3.4091, {x -> -1.20438}}, \ {1.73205, {x -> 0.}}}

$\endgroup$
1
  • $\begingroup$ 0. is not exact. $\endgroup$ – Taiki Apr 3 '15 at 10:11
0
$\begingroup$

You could use FindInstance to find some of the exact stationary points, when mathematica can't solve the equation:

FindInstance[Evaluate[D[A, x]] == 0, x]
(*{{x -> 0}}*)
$\endgroup$
2
  • 1
    $\begingroup$ Did you mean FindInstance[D[A, x] == 0, x]? But still it takes too long. $\endgroup$ – Taiki Apr 3 '15 at 10:09
  • $\begingroup$ @Taiki Yes, thank you $\endgroup$ – Coolwater Apr 3 '15 at 10:31

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.