# Finding the derivative of an absolute value

This one I just don't know how to derive.

$$\ln\|x^4\cos x\|$$

I know the derivative of $$\ln\ x$$, is just $$\frac{1}{x}$$ . It is the absolute value that throws me off. My question is, does the absolute value stay as is or does it disappear?

• $$\frac{1}{|x^4\cos x|}$$
• $$\frac{1}{x^4\cos x}$$

Or is there an extra step that I should preform?

You can actually show that the derivative of $\ln{|x|}$ is $\frac{1}{x}$ for all $x\ne 0$. For $x>0$ this should be clear; for $x<0$, we know $|x| = -x$, and hence we want to calculate $$\frac{d}{dx}(\ln(-x)) = \frac{1}{-x}(-1) = \frac{1}{x}.$$ Once you know that, then you can proceed with the chain rule, as usual.

• Actually you can derive a more general result. If the derivative of $f(x)$ is odd then the same sequence of calculations that you have shown proves that the derivative of $f(|x|)$ equals the derivative of $f(x)$: $$\frac{d}{dx}(f(-x)) = -\frac{d}{dx}(f(x)) \cdot (-1) = \frac{d}{dx}(f(x))$$. Commented Aug 14, 2015 at 11:36

HINT:

$$\frac{d|x|}{dx}=\text{sgn}(x)$$

for $x\ne0$. Now, use the chain rule, but make sure that $x^4 \cos x\ne0$

Let $y=x^4\cos x$. Then, we have $$\frac{d}{dx}\log|x^4\cos x|=\frac{d\log |y|}{d|y|}\text{sgn(y)}\frac{dy}{dx}=\frac{1}{|x^4\cos x|}\text{sgn}(x^4\cos x)(4x^3\cos x-x^4\sin x)=\frac{1}{x^4\cos x}(4x^3\cos x-x^4\sin x)$$Another way to approach the problem is to split it into two parts, (i) $x^4\cos x>0$, and (ii) $x^4\cos x<0$. On Part (i), we have $$\frac{d}{dx}\log|x^4\cos x|=\frac{d}{dx}\log(x^4\cos x)=\frac{1}{x^4\cos x}(4x^3\cos x-x^4\sin x)$$On Part (ii), we have $$\frac{d}{dx}\log|x^4\cos x|=\frac{d}{dx}\log(-x^4\cos x)=\frac{1}{-x^4\cos x}(-4x^3\cos x+x^4\sin x)=\frac{1}{x^4\cos x}(4x^3\cos x-x^4\sin x)$$as expected!

• Sorry, but sgn is unfamiliar to me Commented Aug 14, 2015 at 4:56
• $\text{sgn}(x)$ is the sign function. It is $1$ for $x>0$ and $-1$ for $x<0$. Commented Aug 14, 2015 at 4:58

To elaborate on Dr. MV's answer, we can find the derivative of the absolute value function by noting $$|x|=\sqrt{x^2}$$ and then using the chain rule. The proof goes:

$$\frac d{dx} \sqrt{x^2}=\frac1{2\sqrt{x^2}}\cdot \frac{d}{dx}x^2=\frac{2x}{2\sqrt{x^2}}=\frac{x}{|x|}$$

Now just note that $\frac{x}{|x|}=-1$ if $x<0$ and $\frac{x}{|x|}=1$ for $x>0$.

These kinds of problems can be solved using a simple rule for derivatives of logarithms of absolute functions.

Theorem: For any (univariate) differentiable function $$f$$ we have:

$$\frac{d}{dx} \ln |f(x)| = \frac{f'(x)}{f(x)} \quad \quad \quad \text{for } f(x) \neq 0.$$

Proof: Since $$f$$ is differentiable it is continuous, and so, for any point $$x$$ with $$f(x) \neq 0$$ there exists a neighbourhood $$\mathcal{N}(x)$$ where all values of the function have the same sign as $$f(x)$$ --- i.e., we have: $$\text{sgn} f(x) = \text{sgn} (y) \quad \quad \quad \text{for all } y \in \mathcal{N}(x).$$ Thus, if $$f(x) > 0$$ then $$|f(x)| = f(x)$$ over all points in $$\mathcal{N}(x)$$, and so we have: $$\frac{d}{dx} \ln |f(x)| = \frac{d}{dx} \ln f(x) = \frac{f'(x)}{f(x)}$$ Contrarily, if $$f(x) < 0$$ then $$|f(x)| = -f(x)$$ over all points in $$\mathcal{N}(x)$$, and so we have: $$\ \ \frac{d}{dx} \ln |f(x)| = \frac{d}{dx} \ln (-f(x)) = \frac{-f'(x)}{-f(x)} = \frac{f'(x)}{f(x)}. \ \ \blacksquare$$

Applying this general rule to the case where $$f(x) = x^4 \cos x$$ we have:

$$\frac{d}{dx} \ln |f(x)| = \frac{4 \cos x - x \sin x}{x \cos x} \quad \quad \quad \text{for all } x \neq \cdots, - \frac{3 \pi}{2}, -\frac{\pi}{2}, 0, \frac{\pi}{2}, \frac{3 \pi}{2}, \cdots.$$