# Finding the maximum value on a restricted interval

**URL:** <https://community.wolfram.com/t/finding-the-maximum-value-on-a-restricted-interval/17356>\
**Category:** Questions\
**Tags:** calculus, optimization\
**Created:** [January 5, 2021, 3:38pm UTC](https://community.wolfram.com/t/finding-the-maximum-value-on-a-restricted-interval/17356 "2021-01-05T15:38:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![xkoch](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/xkoch/32/25763_2.png) [@xkoch](https://community.wolfram.com/u/xkoch)\
**Post date:** [January 5, 2021, 3:38pm UTC](https://community.wolfram.com/t/finding-the-maximum-value-on-a-restricted-interval/17356/1 "2021-01-05T15:38:30Z")

</div>

Hi,

I have the following function that I’m trying to maximize with respect to tau, but tau should be in a certain interval. And I know that I’m missing something, but can not find what as when I run my code I do not obtain anything. Maybe I’m using the wrong function, but even with Maxvalue I had the same issue. Any advice would be welcome,

Best,

Xavier Koch

[Function to max.nb](https://community.wolfram.com/uploads/short-url/zUBAOH2Ijci0vVRHfW8T2UsiSL3.nb) (3.63 KB)

---

<div class="post-metadata">

**Author:** ![gianlucagorni](https://avatars.discourse-cdn.com/v4/letter/g/ec9cab/32.png) [@gianlucagorni](https://community.wolfram.com/u/gianlucagorni)\
**Post date:** [January 5, 2021, 5:03pm UTC](https://community.wolfram.com/t/finding-the-maximum-value-on-a-restricted-interval/17356/2 "2021-01-05T17:03:27Z")

</div>

Beware that if you write

```
$Assumptions = a > 0
$Assumptions = \[Beta] > 0

```

the second line overrides the first one. It seems that your assumptions are not compatible with the constraint you impose on the variable `\[Tau]`.

---

<div class="post-metadata">

**Author:** ![xkoch](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/xkoch/32/25763_2.png) [@xkoch](https://community.wolfram.com/u/xkoch)\
**Post date:** [January 6, 2021, 8:50am UTC](https://community.wolfram.com/t/finding-the-maximum-value-on-a-restricted-interval/17356/3 "2021-01-06T08:50:42Z")

</div>

Thanks for your reply, how should I write the assumptions then if this method is not efficient? Also, I don’t see how the constraints could not match as they are just limiting the maximum value [Tau] can take.

---

<div class="post-metadata">

**Author:** ![xkoch](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/xkoch/32/25763_2.png) [@xkoch](https://community.wolfram.com/u/xkoch)\
**Post date:** [January 6, 2021, 9:43am UTC](https://community.wolfram.com/t/finding-the-maximum-value-on-a-restricted-interval/17356/4 "2021-01-06T09:43:02Z")

</div>

I’ve noticed that the original file is from an advanced version and not everyone can open it so here’s a better version.

[Function to max 1.nb](https://community.wolfram.com/uploads/short-url/qkZruCIrrE7svgaejz5sNdpFEZI.nb) (6.65 KB)

---

<div class="post-metadata">

**Author:** ![gianlucagorni](https://avatars.discourse-cdn.com/v4/letter/g/ec9cab/32.png) [@gianlucagorni](https://community.wolfram.com/u/gianlucagorni)\
**Post date:** [January 6, 2021, 11:09am UTC](https://community.wolfram.com/t/finding-the-maximum-value-on-a-restricted-interval/17356/5 "2021-01-06T11:09:38Z")

</div>

To make more than one assumption I would use `And`:

```
$Assumptions = And[a > 0, \[Beta] > 0, d > 0, 1 > b > 0,
  c > 0, a > \[Tau]*\[Theta]A, \[Tau] > 
   0, \[Theta]A > \[Theta]B > \[Theta]C, a > \[Tau]*\[Theta]B,
  a > \[Tau]*\[Theta]C, Fb > 0, Fc > 0, 1 > \[Alpha] > 0]

```

Your constraint is then

```
myConstraint = Simplify[\[Tau] < 1/(2 (-\[Theta]A^2 + \[Theta]B^2))*
    (-2 a \[Theta]A + 2 a \[Theta]B - 
      Sqrt[((2 a \[Theta]A - 2 a \[Theta]B)^2 - 
         4 (-\[Theta]A^2 + \[Theta]B^2)*
           (-((a^2 \[Theta]A)/(\[Theta]A + \[Theta]B)) - (
            a^2 \[Beta] \[Theta]A)/(\[Theta]A + \[Theta]B) + (
            a^2 p \[Beta] \[Theta]A)/(\[Theta]A + \[Theta]B) - (
            a^2 p \[Alpha] \[Beta] \[Theta]A)/(\[Theta]A + \[Theta]B) \
+ (a^2 \[Theta]B)/(\[Theta]A + \[Theta]B) +
            (a^2 \[Beta] \[Theta]B)/(\[Theta]A + \[Theta]B) - (
            a^2 p \[Beta] \[Theta]B)/(\[Theta]A + \[Theta]B) + (
            a^2 p \[Alpha] \[Beta] \[Theta]B)/(\[Theta]A + \
\[Theta]B)))])]

```

I retract what I said about incompatibility: I had miswritten a symbol. Your constraint is indeed an interval, but its endpoints have different expressions, depending on the parameters:

```
intrvl =Reduce[myConstraint && $Assumptions, \[Tau], Reals]

```

To maximize a parametric expression, `FindMaxValue` is not suitable, because it uses numerical methods. `MaxValue` can handle symbolic expressions:

```
fnct = -((d (a - \[Theta]A \[Tau])^2)/(2 (b + c)^2)) + (
   b (1 + \[Beta]) (a - \[Theta]A \[Tau])^2)/(8 (b + c)^2) +
   ((1 + \[Beta]) (a - \[Theta]A \[Tau])^2)/(4 (b + c));
MaxValue[{fnct, intrvl}, \[Tau]]// Simplify

```

The interpretation of the symbolic result is tricky.
