# Find the maximum value of a function of $x$ for a given range of values of $x$

What is the most efficient and reasonable way to find the maximum value of a function of $x$ within a given range of $x$ values?

For example, given the function $f(x)=3\sin(x)+0.01x^2$, how can I find the maximum between $x=0$ and $x=37$, inclusive. I'm not really looking for the specific answer to this, but the general principle that can be used for any equation. I seem to have forgotten how to do this.

-

You take the derivative $f^\prime$ and find out the points $x$ where it's zero: $f^\prime (x) \stackrel{!}{=} 0$

$f^\prime (x)$ is the slope at $x$. If it's zero it means that you have a found either a minimum, a maximum or a saddle point. You're not interested in saddle points though so you want to check that the points where $f^\prime$ is zero also have the property that $f^{\prime \prime}$ is non-zero. $f^{\prime \prime}$ gives you a measure for the "curvature" of $f$ at that point. Saddle points are horizontal hence have $f^{\prime \prime}$ equal to zero.

Edit As pointed out in the comment by Ronald, $f^{\prime \prime} = 0$ is not a sufficient condition to be at a saddle point. There are functions that satisfy this condition at points where they don't have a saddle point, such as for example $f(x) = x^4$ at $0$. In general you need to look at the first derivative that's non-zero, this is called "higher-order derivative test".

Note that for example if $f$ is a function like $f(x) = x$ then it won't have any points where $f^\prime$ is zero and yet it will attain a maximum at the right end of your interval. To detect this case you simply have to remember to also check $f(a)$ and $f(b)$ if your function is defined on $[a,b]$.

For this you need $f$ to be differentiable. Luckily, your example and probably many of the functions you'll have to find mins and maxs for will be differentiable.

-
strictly speaking $f'=0$ and $f'' = 0$ does not necessarily indicate a saddle point. –  Ronald Apr 12 '12 at 23:38
@Ronald Thank you for pointing this out, I added it to my answer. –  Matt N. Apr 13 '12 at 7:48