Derivative of |1-x^2|

The derivative of \( |1-x^2| \).

A graph shows that there are issues with this function due to the “kinks” at \( -1 \) and \( 1 \):

curve(abs(1 - x^2), -2, 2)

plot of chunk unnamed-chunk-1

So be careful. The chain rule will apply outside of those values though:

Here are the key functions:

\[ f(x) = |x|, \quad \text{and} \quad g(x) = 1 - x^2 \]

With derivatives:

\[ f'(x) = -1 \text{ when } x < 0 \text{, } +1 \text{ when } x > 0 \quad \text{ and } DNE \text{ when } x=0; \quad \text{ and } g'(x) = - 2x \]

The chain rule says the derivative of \( |1-x^2| \) is \( f'(g(x)) g'(x) \).

Now we need to know when \( g(x) < 0 \) and \( g(x) > 0 \) to use the derivative, \( f'(x) \). We see that \( g(x) \) is positive on \( (-1,1) \), 0 at both 1 and -1, and negative otherwise. So \( f'(g(x)) \) does not exists at -1 and 1, is \( 1 \) inside \( (-1, 1) \) and is \( -1 \) outside of \( [-1,1] \).

To finish we need to multiply by \( g'(x) \):

\[ f'(x) = \begin{cases} -1 \cdot(-2x) & x < -1 \text{ or } x > 1, \\ +1 \cdot(-2x) & -1 < x < 1. \end{cases} \]

Let's graph it to check. We should be negative to the left of -1 and between 0 and 1, otherwise positive.

## no simple way to plot
a <- stepfun(x = c(-1, 1), y = c(-1, 1, -1))
f <- function(x) a(x) * -2 * x
x <- seq(-2, 2, length.out = 1001)
x[x == 1 | x == -1] <- NA
plot(x, f(x), type = "l")

plot of chunk unnamed-chunk-2