<s>[INST] Finding the maximum value of $f(x)=\frac{|x|-2-x^2}{|x|+1},x\in\mathrm R$ Question:
Find the maximum value of $f(x)=\frac{|x|-2-x^2}{|x|+1},x\in\mathrm R$
My Attempt:
I took two cases. One where $x\ge0$, so, $|x|=x$ and another where $x\le0$, so, $|x|=-x$. Then I cross multiplied, made a quadratic in $x$ and wrote discriminant greater than equal to zero. Accordingly, I got range of $f(x)$.
I wonder if there is another way to solve this question, where we don't have to take two cases.
 [/INST] Perhaps surprisingly, $ \ f(x) \ = \ \large{\frac{|x| \ - \ 2 \ - \ x^2}{|x| \ + \ 1} } \ $ is an even function(!).  If we consider $ \ f_{+}(x) \ = \ \large{\frac{ x \ - \ 2 \ - \ x^2}{ x \ + \ 1} }  $ $ = \ (-x + 2) - \frac{4}{x + 1}   \ \ , \ $ the corresponding curve has a vertical asymptote of $ \ x \ = \ -1 \ $ and an "oblique" asymptote $ \ y \ = \ -x + 2 \ \ ; \ $  the branch for $ \ x \ > \ -1 \ $ lies "below" the oblique asymptote, making $ \ f_{+}(x) \ < \ 0 \ \ , \ $ while the branch for $ \ x \ < \ -1 \ $ lies "above" that asymptote and so $ \ f_{+}(x) \ > \ 0 \ \ $ there.  The function $ \ f_{-}(x) \ = \ \large{\frac{ -x \ - \ 2 \ - \ x^2}{ -x \ + \ 1} } \ = \ \normalsize{( x + 2) - \frac{4}{1 - x}  } \ \ $ is the "horizontal reflection" of $ \ f_{+}(x) \ \ , \ $ thus $ \ f_{-}(x) \ > \ 0 \ \ $ for $ \ x \ > \ +1 \ $ and $ \ f_{-}(x) \ < \ 0 \ \ $ for $ \ x \ < \ +1 \ \ . $  [These individual functions have no symmetry, but the presence of the absolute-value brackets leads to $ \ f(x) \ = \ f(-x) \ \ . \ ] $
Our function curve is then the union of the portions of $ \ f_{+}(x) \  \ $ "to the right" of the $ \ y-$axis and of $ \ f_{-}(x) \  \ $ "to its left", which produces a symmetrical curve "below" the two asymptote lines with its $ \ y-$intercept at $ \ (0 \ , \ \frac{0 \ - \ 2 \ - \ 0^2}{0 \ + \ 1} = -2) \ \ . \ $  (The "positive" branches and vertical asymptotes of the individual curves are excluded.)
To find the relative (and also global) extrema of this curve, we may solve either
$$  f'_{+}(x) \ \ = \ \  \frac{ -x^2 \ - \ 2x \ + \ 3}{ (x \ + \ 1)^2} \ \ = \ \ -\frac{ (x - 1)·(x + 3)}{ (x \ + \ 1)^2} \ \ = \ \  0 \ \ \ \text{or} $$
$$  f'_{-}(x) \ \ = \ \  \frac{ -x^2 \ + \ 2x \ + \ 3}{ (1 \ - \ x)^2} \ \ = \ \ -\frac{ (x + 1)·(x - 3)}{ (1 \ - \ x)^2} \ \ = \ \  0 \ \ . $$
[We can alternatively differentiate the "quotient-remainder" expressions for the functions, producing $ \ f'_{+}(x) \ \ = \ \ -1 \ + \frac{4}{(x + 1)^2} \ = \ 0 \ $ or $ \ f'_{-}(x) \ \ = \ \ 1 \ - \frac{4}{(1 - x)^2} \ = \ 0 \ \ , \ $ again needing to apply the appropriate interval restriction to remove the "spurious" solution.]
[ADDENDUM (8/5) -- We can also find this maximum without calculus by asking what "horizontal line" $ \ y \ = \ c \ $ intersects, say, $ \ f_{+}(x) \ $ at a single point:
$$ \frac{ x \ - \ 2 \ - \ x^2}{ x \ + \ 1} \ \ = \ \ c \ \ \Rightarrow \ \ x^2 \ + \ (c - 1)·x \ + \ ( c + 2 ) \ \ = \ \ 0 \ \ , $$
which has the determinant $ \ (c - 1)^2 - 4·(c + 2) \ = \ c^2 - 6c - 7 \ = \ (c + 1)·(c - 7) \ \ . \ $  This equals zero for $ \ c \ = \ -1 \ \ , \ $ which is the maximum at $ \ x \ = \ 1 \ \ , \ $ and at $ \ c \ = \ 7 \ \ , \ $ which is the minimum at $ \ x \ = \ -3 \ \ $ on the "excluded" branch of the function curve.]
Within their applicable intervals, the derivative for $ \ f_{+}(x) \ $ is zero for $ \ x \ = \ +1 \ $ and that for $ \ f_{-}(x) \ $ is zero for $ \ x \ = \ -1 \ \ . \ $  The (global) maximum for $  \ f(x) \ $ is therefore
$$   f_{+}(1) \ \ = \ \  (-1 + 2) - \frac{4}{1 + 1}  \ \ = \ \ f_{-}(-1) \ \ = \ \  ([-1] + 2) - \frac{4}{1 - [-1]} \ \ = \ \ -1 \ \ .  $$
Knowing where the curve is relative to its asymptote lines, we can be assured that these are global maxima.  (The second derivatives are a bit complicated, but do prove to be negative.)

</s>