# Minimize doesn't work for a given function

**URL:** <https://community.wolfram.com/t/minimize-doesnt-work-for-a-given-function/23722>\
**Category:** Questions\
**Tags:** optimization\
**Created:** [March 13, 2024, 11:49am UTC](https://community.wolfram.com/t/minimize-doesnt-work-for-a-given-function/23722 "2024-03-13T11:49:33Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![gabriybarra](https://avatars.discourse-cdn.com/v4/letter/g/e56c9b/32.png) [@gabriybarra](https://community.wolfram.com/u/gabriybarra)\
**Post date:** [March 13, 2024, 11:49am UTC](https://community.wolfram.com/t/minimize-doesnt-work-for-a-given-function/23722/1 "2024-03-13T11:49:33Z")

</div>

I’m trying to minimize the function V(phi) using the code below

```
a =.
f =.
th =.
mu =.
md =.
V[phi_] := -2 * (mu Cos[phi + th/2] + md Cos[phi - th/2])
Minimize[V[phi], phi]

```

But the output is just the command itself!

```
Out: Minimize[-2 (md Cos[phi - th/2] + mu Cos[phi + th/2]), phi]

```

What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![eric3](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/eric3/32/12760_2.png) [@eric3](https://community.wolfram.com/u/eric3)\
**Post date:** [March 13, 2024, 2:30pm UTC](https://community.wolfram.com/t/minimize-doesnt-work-for-a-given-function/23722/2 "2024-03-13T14:30:20Z")

</div>

I’m not sure what you expect when you don’t have any constraints on the other symbols used in `V`. No matter what value you try for `phi`, `md` and `mu` could dominate and make the result arbitrarily large or small.

---

<div class="post-metadata">

**Author:** ![gabriybarra](https://avatars.discourse-cdn.com/v4/letter/g/e56c9b/32.png) [@gabriybarra](https://community.wolfram.com/u/gabriybarra)\
**Post date:** [March 13, 2024, 3:12pm UTC](https://community.wolfram.com/t/minimize-doesnt-work-for-a-given-function/23722/3 "2024-03-13T15:12:06Z")

</div>

Right. How do I add the constraints? I tried to use

```
`$Assumptions = th >= 0 && mu >= 0 && md >= 0`

```

but without much success…

---

<div class="post-metadata">

**Author:** ![ivanovdenis710616](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/ivanovdenis710616/32/34915_2.png) [@ivanovdenis710616](https://community.wolfram.com/u/ivanovdenis710616)\
**Post date:** [March 13, 2024, 3:55pm UTC](https://community.wolfram.com/t/minimize-doesnt-work-for-a-given-function/23722/4 "2024-03-13T15:55:42Z")

</div>

This is very strange. Even

```
Minimize[{Cos[x + a/2], {0 <= x <= 2\[Pi], 0 < a < 1}}, x]

```

not work.  
There are similar question on MSE: [[1]](https://mathematica.stackexchange.com/questions/272472/mathematica-failing-to-minimize-with-parameters)[[2]](https://mathematica.stackexchange.com/questions/164738/why-does-this-minimization-with-parameters-does-not-work)  
The answers suggest add `a` to variables of minimization:

```
Minimize[{Cos[a/2 + x], {0 <= x <= 2\[Pi], 0 < a < 1}}, {a, x}]
Out: {-1, {a -> 9/34, x -> 1/68 (-9 + 68 \[Pi])}}

```

But this is bad cheating, cause we need parametric solution!  
In docs there is example with fully parametric solution for `ax^2+b x + c`.  
I’m going to post revisited question on MSE and query for Support team.

---

<div class="post-metadata">

**Author:** ![ivanovdenis710616](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/ivanovdenis710616/32/34915_2.png) [@ivanovdenis710616](https://community.wolfram.com/u/ivanovdenis710616)\
**Post date:** [March 13, 2024, 4:46pm UTC](https://community.wolfram.com/t/minimize-doesnt-work-for-a-given-function/23722/5 "2024-03-13T16:46:48Z")

</div>

Well, we can use mathematical analysis.  
If we want to find \min of -2 \cdot f then we need to find \max of f.  
So it is root of first derivative with negative second derivative.  
I rewrote your expression a little for simplicity, so we try this:

```
Clear[a, b, t, V];
V[x_] := a Cos[x + t/2] + b Cos[x - t/2];

```

And if we run next code, in 15-20 sec (on average laptop) we get big dump,  
but with meaningful and useful results:

```
goal = D[V[x], x];
secDeriv = D[V[x], {x, 2}];
Reduce[goal == 0 && secDeriv < 0 && 0 <= x <= 2 \[Pi], x, Reals]

```

---

<div class="post-metadata">

**Author:** ![gabriybarra](https://avatars.discourse-cdn.com/v4/letter/g/e56c9b/32.png) [@gabriybarra](https://community.wolfram.com/u/gabriybarra)\
**Post date:** [March 13, 2024, 5:05pm UTC](https://community.wolfram.com/t/minimize-doesnt-work-for-a-given-function/23722/6 "2024-03-13T17:05:41Z")

</div>

Thanks man!! It’s so weird that you cannot just use Minimize/Maximize

---

<div class="post-metadata">

**Author:** ![ivanovdenis710616](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/ivanovdenis710616/32/34915_2.png) [@ivanovdenis710616](https://community.wolfram.com/u/ivanovdenis710616)\
**Post date:** [March 13, 2024, 5:15pm UTC](https://community.wolfram.com/t/minimize-doesnt-work-for-a-given-function/23722/7 "2024-03-13T17:15:41Z")

</div>

Well, I like Mathematica, in many ways it’s cool thing! So I report this issue as bug,  
looks like problem in trig functions.

---

<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:** [March 15, 2024, 8:46am UTC](https://community.wolfram.com/t/minimize-doesnt-work-for-a-given-function/23722/8 "2024-03-15T08:46:55Z")

</div>

Parametric minimization seems to be supported only in the algebraic case. You can algebrize your trigonometric problem, though:

```
subst = {Cos[phi] -> x, Sin[phi] -> y};
TrigExpand[V[phi]] /. subst
Minimize[{%, x^2 + y^2 == 1}, {x, y}]
% /. Map[Reverse, subst]
% // Simplify

```

---

<div class="post-metadata">

**Author:** ![ivanovdenis710616](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/ivanovdenis710616/32/34915_2.png) [@ivanovdenis710616](https://community.wolfram.com/u/ivanovdenis710616)\
**Post date:** [March 15, 2024, 8:52am UTC](https://community.wolfram.com/t/minimize-doesnt-work-for-a-given-function/23722/9 "2024-03-15T08:52:55Z")

</div>

Very smart idea!
