1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Derivative of piecewise function(split in 3 regions)

  1. Aug 12, 2013 #1
    I use the general formula: if y=|f(x)| then y'=[itex]\frac{d|f(x)|}{dx}= \frac{f(x)*f'(x)}{|f(x)|}[/itex] to calculate the derivative of the piecewise function given below.

    Given: Piecewise function
    $$h(y)=\alpha(m_1 y+\frac{1}{2}(m_0 - m_1)(|y+1|-|y-1|))$$

    My attempt at calculating the derivative:
    $$\frac{\mathrm{d} h}{\mathrm{d} y}=\alpha m_1+\alpha 0.5(m_0-m_1)(\frac{y+1}{|y+1|}-\frac{y-1}{|y-1|})$$, is this right?
    Last edited: Aug 12, 2013
  2. jcsd
  3. Aug 12, 2013 #2

    Stephen Tashi

    User Avatar
    Science Advisor

    That general formula isn't correct.
  4. Aug 12, 2013 #3
    Is it correct now?I edited it.
  5. Aug 12, 2013 #4

    Stephen Tashi

    User Avatar
    Science Advisor

    Yes and I think you have the correct answer to the problem.
  6. Aug 15, 2013 #5


    User Avatar
    Science Advisor

    Another way to look at this is to separate it unto three parts (that is, treat it as being "piecewise" as you say in your title. If y< -1, then both y+ 1 and y- 1 are negative so |y+1|- |y- 1|= -(y+1)-(-(y- 1)= -y- 1+ y- 1= -2. That is a constant so its derivative is 0. If [itex]-1\le y< 1[/itex], then y+1 is positve but y- 1 is still negative. |y+ 1|- |y- 1|= y+ 1- (-(y-1))= y+ 1+ y- 1= 2y. The derivative of that is 2. Finally, if [itex]y\ge 0[/itex], both y+ 1 and y- 1 are positive so |y+ 1|- |y- 1|= y+ 1- y+ 1= 2. Again the derivative of that is 0.

    So the derivative of the original function is [itex]\alpha m_1[/itex] if y< -1, [itex]\alpha m_1- (m_0- m_1)[/itex] if -1< y< 1, and [itex]\alpha m_1[/itex] if y> 1. Of course, the function is not differentiable at -1 or 1.

    Looking at your proposed derivative, if y< -1, so that both y-1 and y+ 1 are negative, the last part is "-1- (-1)" which is 0 while if y> 1, so that y-1 and y+ 1 are positive, it is "1- 1". If -1< y< 1, then it is "1- (-1)= 2" which cancels the "1/2" so, yes, that is the same thing.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook