# Derivative of a function with variable range

Suppose for example that I have a function $g_y(x)$ such that

$g_y(x) = \begin{cases} y+x &\mbox{if } -x<y<1-x \\ 1 & \mbox{if } y>1-x \\0 &\mbox{if } y<-x \end{cases}$

How, if possible, would I find $\frac{dg}{dx}$?

Edit: Also, I need to have that $x\in (0,1)$

-

$$g_y(x) = \begin{cases}0 & \text{if } x < -y\\ x+y & \text{if }x \in (-y,1-y)\\ 1 & \text{if }x > 1-y\end{cases}$$ You also need $x \in (0,1)$. We will split it into cases depending on where $y$ lies.

If $y \leq -1$, then we get that $g_y(x) = 0$ for all $x \in (0,1)$.

If $-1 \leq y \leq 0$, then we get that $$g_y(x) = \begin{cases}0 & \text{if } x \in (0,-y)\\ x+y & \text{if }x \in (-y,1)\end{cases}$$ for all $x \in (0,1)$.

If $0 \leq y \leq 1$, then we get that $$g_y(x) = \begin{cases} x+y & \text{if }x \in (0,1-y)\\ 1 & \text{if }x \in(1-y,1)\end{cases}$$ for all $x \in (0,1)$.

If $y \geq 1$, then we get that $g_y(x) = 1$ for all $x \in (0,1)$.

Now you should be able to work out the derivative with relative ease. Note that if $y \in [-1,0]$, then the function is not differentiable at $-y$ and for $y \in [0,1]$, the function is not differentiable at $1-y$.

-