# Find the extrema of $f(x)=(x^2+2x-7)e^{|x+2|}$

I need to find the extrema of $$f(x)=(x^2+2x-7)e^{|x+2|}$$. The first derivative is $$e^{|x+2|}(2x+2+(x^2+2x-7)(|x+2|)')$$. Looking at two cases where $$x<-2$$ or $$x>-2$$ gives two extrema - at the points -3 and 1. And now comes the real question: Is there an extremum at the point -2 and why? If we replace x with -2, the first derivative equals -2. But the fact that the derivative there isn't $$0$$ doesn't mean there isn't an extremum. In fact, if I take a look at the graphic of the function, it is obvious that in the region of -2, the value of the function for $$x=-2$$ is the highest. So, according to the definition, there should be a local maximum. Which one is true? Is $$x=-2$$ a local maximum and why?

• How did you get extrema "at the points $=3$ and $1$"? [show what you did] Commented Dec 24, 2020 at 17:08
• Case1: $x<-2$, therefore the module brackets are removed and the content is taken with a negative sign. (instead of $|x+2|$, we get $-(x+2)=-x-2. (-x-2)'=-1$, etc. Case2: $x>-2$, therefore the module brackets are removed and the content is taken with a positive sign. (instead of $|x+2|$, we get $(x+2). (x+2)'=1$, etc. Commented Dec 24, 2020 at 17:13

## 2 Answers

The derivative of $$|x+2|$$ is $$\dfrac {x+2}{|x+2|} = sgn(x+2) := \begin{cases} 1 &\text{ for } x+2 > 0\\-1 &\text{ for } x+2 < 0 \end{cases}$$ and is not defined for $$x=-2$$. Therefore the derivative of $$f(x)$$ is also not defined for $$x=-2$$. (Some textbooks include these points where $$f'(x)$$ is not defined as critical points; regardless one must check whether an extremum exists at these points.)

The first derivative test can still be applied by taking left/right limits. Note that:

$$\lim_{x \to -2^-} f'(x) = \lim_{x \to -2^-} e^{|x+2|}\left(2x+2+(x^2+2x-7)\dfrac {x+2}{|x+2|}\right)=e^0(-4+2+(4-4-7)(-1))=5$$

$$\lim_{x \to -2^+} f'(x) = \lim_{x \to -2^+} e^{|x+2|}\left(2x+2+(x^2+2x-7)\dfrac {x+2}{|x+2|}\right)=e^0(-4+2+(4-4-7)(1))=-5$$

This shows that the function is increasing before $$-2$$ and decreasing after $$-2$$, and thus there is a local maximum at $$x=-2$$.

A similar analysis can be carried out on a simpler function: $$|x|$$. It is not differentiable at $$x=0$$, but has a local minimum there.

Hint: You can simplify a lot the problem taking the $$\log$$ of your function and studying the extrema of the new function.

Indeed $$f(x)= (x^2 +2x -7)e^{|x+2|}$$ has the same extrema of $$g(x)= \log[(x^2 +2x -7)e^{|x+2|}]$$ and you can easily see that $$g(x)= \log[(x^2 +2x -7)e^{|x+2|}] = \log(x^2 +2x -7) + |x+2|$$

The extrema are the same since the log is a strictly increasing function and the composition of any function with a strictly increasing function does not change the extrema.