for h=0.2

I'm trying to find the maximum value of


subject to

8.1 < x < 8.5

I've tried pretty much every combination of:


FindMaximum[], MaxValue[]

Region (reg):

x \ [Element] Interval[{8.1,8.5}]
x \ [Element] Interval[8.1,8.5]
x, Interval[{8.1,8.5}]
x, Interval[8.1,8.5]
x \ [Element] Interval[{8.1,8.5}], x
x \ [Element] Interval[8.1,8.5], x

I even tried using 81/10 and 85/10 but that didn't work either..


{(-h^2/3)*(-1/x^2) , reg}
Assuming[reg , -h^2/(3*x^2)

I'm getting errors like:

The variable x\[Element]Interval[{81/10,17/2}] cannot be localized so that it can be assigned to numerical values.

The variable x\[Element]Interval[{8.099999999,8.500000001}] cannot be localized so that it can be assigned to numerical values.

Constraints in {x\[Element]Interval[{8.099999999,8.500000001}]} are not all equality or inequality constraints. With the exception of integer domain constraints for linear programming, domain constraints or constraints with Unequal (!=) are not supported.

One time it told me the max value of this function was -7.34642395*10^-35.

Honestly I know I'm doing something really stupid but I can't figure out what.

  • $\begingroup$ With[{h = 0.2}, FindMaximum[{(-h^2/3)*(-1/x^2), 8.1 <= x <= 8.5}, {x, 8.3}]]? $\endgroup$
    – march
    Feb 29, 2016 at 19:09
  • $\begingroup$ This doesn't seem to be working. I had to tweek it a bit for what I was using it for after I posted the question. It works better than what I have but I have:............... With[{h = 0.2}, FindMaximum[{Abs[(h^2/3)*(-1/x^2)], 8.3 <= x <= 8.7}, x]] = {0.000193497, {x -> 8.30103}} ...............But............... Abs[(-0.2^2/(3*8.3^2))] = 0.0001935452654 $\endgroup$
    – Kvo
    Feb 29, 2016 at 19:31

2 Answers 2


You should be aware of the fact that your problem may be somewhat ill-posed. Your function simplifies to the following expression:


(* Out: h^2/(3 x^2) *)

The difference of the function's values at the two extrema of your interval is ca. $0.0005\ h^2$. Since $h^2$ is a positive quantity (for $h\ne0$) and the function is monotonically decreasing (plot it), its maximum is attained at $x=8.1$, i.e. infinitesimally outside the region defined by your constraints; in that case Maximize & co. will return the supremum and the closest specifiable point (from the docs).

Many approaches seem to produce a result when correct syntax is used:

FindMaximum[{(-h^2/3)*(-1/x^2), 8.1 < x < 8.5}, x]
Maximize[{(-h^2/3)*(-1/x^2), 8.1 < x < 8.5}, x]

However, I was intrigued by the idea of using an Interval as a region specification, although technically it is NOT equivalent to your desired constraints, because Interval[{8.1, 8.5}] represents the closed interval that includes both end points (i.e. $8.1\le x\le8.5$, whereas you want them excluded.

My first attempt had me scratching my head though:

Maximize[(-h^2/3)*(-1/x^2), x ∈ Interval[{8.1, 8.5}]]

Mathematica graphics

It turns out that the accepted syntax for specifying that $x$ belongs to that interval is {x} ∈ Interval[{8.1, 8.5}]. Using that form, the optimization works fine:

Maximize[(-h^2/3)*(-1/x^2), {x} ∈ Interval[{8.1, 8.5}]]
(* Out: {0.000203221, {x -> 8.1}} *)

This did not strike me as immediately obvious, nor did I find it referenced in the documentation for Interval or other optimizers that accept geometric regions. I am still wondering whether I am missing something and I should have expected that. Hopefully I'll update if I find out more.

  • $\begingroup$ the requirement for the { } is inconsistent with the docs for Element. Possibly should be labeled as a bug? $\endgroup$
    – george2079
    Feb 29, 2016 at 19:54
  • $\begingroup$ @george2079 Use of vectors ({ }) is consistent when you consider Interval to be a geometric region when Element is used with it. Points in geometric regions are always coordinates that are described by vectors, even when those vectors are of only one dimension. Plain x is also valid, but at that case it's considered to be a symbolic vector, which needs to be handled accordingly (for instance, with Indexed[x, 1] in equations, instead of being treated as a number. $\endgroup$
    – kirma
    Feb 29, 2016 at 20:12
  • $\begingroup$ For symbolic vector case, consider Maximize[(-h^2/3)*(-1/Indexed[x, 1]^2), x \[Element] Interval[{8.1, 8.5}]] (* {0.000203221, {x -> {8.1}}} *) $\endgroup$
    – kirma
    Feb 29, 2016 at 20:15
  • 2
    $\begingroup$ Makes sense, but I still find the docs lacking. $\endgroup$
    – george2079
    Feb 29, 2016 at 21:16

This is really an extended comment about region-based constrained variables.

When you see Element in the variable section of a function such as Maximize, it always means you are dealing with geometric regions, although it is not necessarily immediately obvious. Values in geometric regions are always vectors, even when that vector has a length of one. So it happens to be in the case of Interval, when it is interpreted to be a region. Like some graphics primitives, Interval has second meaning in this context. This kind of constrained variable is declared in a form like Element[{x}, Interval[{0, 1}]]. Compare this with Element[{x, y}, Disk[]].

So, such declarations should have curly braces, right? Not quite. There are also symbolic vectors which are a feature that isn't documented very well. They don't have curly braces, even if they involve both Element and a geometric region. These are such as Element[v, Interval[{0, 1}]] or Element[v, Disk[]]. Sometimes these symbolic vectors can be used directly also on the equation side; consider Maximize[Norm[v], Element[v, Disk[]]], for instance. (Sadly mixing normal and symbolic vectors doesn't work as nicely as one might hope.)

This form allows for accessing individual components of symbolic vectors using Indexed, which is used like this: Maximize[Indexed[x, 1] - Indexed[x, 1]^2, Element[x, Interval[{0, 1}]]].

Note that in case of list-based coordinates, results list those variables as individual scalars:

Maximize[y + x^2, Element[{x, y}, Disk[]]]

(* {5/4, {x -> -(Sqrt[3]/2), y -> 1/2}} *)

... but in the case of symbolic vectors, as vector values:

Maximize[Indexed[v, 2] + Indexed[v, 1]^2, Element[v, Disk[]]]

(* {5/4, {v -> {-(Sqrt[3]/2), 1/2}}} *)

Interval is just one of these regions that can be used, and its elements are also vectors.

EDIT: A side note: FindMaximum doesn't understand region constraints in the variable declaration part. This is understandable, but unfortunately it doesn't understand that in its constraints either, which saddens me. This does work, though (as it expands to normal inequalities):

With[{h = 0.2}, 
   RegionMember[Interval[{8.1, 8.5}], {x}]}, x]]

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.