# Constructing a function that is continuous and has a max on an open interval, but is not necessarily increasing immediately to the left of the max.

This is a homework problem for my real analysis class. It is problem 13.1 from Mattuck's Introdution to Analysis. The question reads:

Suppose F(x) is continuous on some open interval I and c is a maximum point inside this interval. Is it true that f(x) must be increasing immediately to the left of c and decreasing immediately to the right of c? Proof or counterexample. (Note: A constant function is considered to be both increasing and decreasing.)

My friend and I have been attempting to find a counterexample. We figured a function that begins oscillating infinitely many times near c but converges to c would work. We're having difficulty constructing such a function out of elementary functions so we think we will have to define it in another way, piece-wise using receding intervals. I have no clue how this would look. Any advice would be greatly appreciated.

-

$$f(x) = x^2\left(-2+\sin\frac1x\right)$$ when $x\ne0$, and $f(0)=0$.

By squeezing, you can see that this is continuous at $0$

Since $\sin(\text{anything})\le 1$, we have $-2+\sin\dfrac1x\le-1$, so $f(x)\le -x^2$, but $f(x) = 0$. So it has a global maximum at $0$.

Now work on showing that no matter how close to $0$ you get, there are places where the derivative has the wrong sign for $f$ to satisfy the false conjecture.

-
Oh wow. That is really neat. Thank you. –  Barber8 Nov 16 '12 at 19:10

Your original idea sounds good to me. For example, you could start with the function $$f(x) = \begin{cases}x \sin(1/x) & \text{if } x \ne 0 \\ 0 & \text{if } x = 0, \end{cases}$$

which is continuous on the entire real line and differentiable everywhere except at zero, and looks like this in the vicinity of zero:

Then you just need to tweak $f$ to have a global maximum at $x = 0$, for example by subtracting $2|x|$ from it. The resulting function $g(x) = f(x)-2|x|$ looks like this in the vicinity of zero:

Ps. If you want a counterexample which is even differentiable everywhere, try $$h(x) = x f(x) - 2x^2 = \begin{cases}x^2 \sin(1/x) - 2x^2 & \text{if } x \ne 0 \\ 0 & \text{if } x = 0, \end{cases}$$ which looks like this:

Proving that $h$ is differentiable at zero is fairly easy from first principles, just by showing that the difference quotient $$\frac{h(x)-h(0)}{x} = x \sin(1/x) - 2x$$ converges to $0$ in the limit as $x \to 0$, which in turn can be done using the squeeze theorem in exactly the same way as for showing the continuity of $f$ and $g$ at zero. Then you just need to show that the derivative of $h$ takes both positive and negative values on every interval with one endpoint at zero.

-

There are a few approaches to this. Both of your ideas will work – for a function that oscillates infinitely many times, $\sin\left(\frac{1}{x}\right)$ tends to come in handy. It doesn't immediately do what you want (it's not continuous at zero), but with a little persuading it'll fit.

But the other answers have already covered this, so here's a piecewise construction: you want a global maximum, let's say $(0,0)$. Now basically what you want is, on every interval to the left or right of the global maximum, you spend some time going up and some time going down. So, go up from $(-1,-1)$ to $x = -1/2$, then go down until $x = -1/4$, then go up until $x = -1/8$... this is clearly going to work as long as you can make it continuous. But that's not hard: make it piecewise linear and make the distance you travel on each downstroke tend to $0$ as you get closer to $x=0$. Then flip in the $y$-axis to get the other side.

If you think about it, it's pretty easy to come up with continuous functions with unique global maxima. Consider this moustache-shaped region:

courtesy of Wolfram|Alpha. Any function that stays within it will be forced to have a maximum at 0 and continuous at 0. In the blue region, you can wiggle up and down all you want, however you wish, as long as you remain continuous, which isn't too hard. Wiggle nicely up to near the centre, then "zoom in", and close up, the region looks exactly as it did before, so you can wiggle exactly as you did before you zoomed in.

-
That's fantastic, thank you. –  Barber8 Nov 16 '12 at 18:55

Define $f:\mathbb{R}\rightarrow\mathbb{R}$ by

$$\left\{ \begin{array}{rcl} f(x)&:=-|x\sin\frac{1}{x}|,&\text{if }x\neq 0,\\ &=0,&\text{otherwise}. \end{array} \right.$$

-
Not a great homework answer – doesn't really explain. –  Ben Millwood Nov 16 '12 at 18:21