how to find subdifferential of a function $x^2+ |x-1|+|x-2|$ Given a function
$f(x) =  x^2+ |x-1|+|x-2| $
find it's subdifferential.
My approach to solving this was to divide the answer into 5 parts:

*

*For |x-1|>1 and |x-2|>2
$f(x) = x^2+ x-1+x-2$ and $f'(x) = 2x+2$


*For |x-1|<1 and |x-2|<2
$f(x) = x^2-(x-1)-(x-2)$ and $f'(x) = 2x-2$


*For |x-1|>1 and |x-2|<2
$f(x) = x^2+(x-1)-(x-2)$ and $f'(x) = 2x$


*For |x-1|<1 and |x-2|>2
$f(x) = x^2-(x-1)+(x-2)$ and $f'(x) = 2x$


*For |x-1|=1 and |x-2|=2
$ f(x) = x^2$ and $f'(x) = 2x$
Does this look right? Is this the correct approach?

First, I have to admit I am not familiar with a "subdifferential".  It look to me like you are just taking the derivative.  Second, dividing with things like "|x- 1|> 1 and |x- 2|> 2" is confusing and probably not what you want.  Instead divide the real line into three intervals: $x\le 1$, $1< x\le 2$, and $x> 2$.
For $x\le 1$ both x-1 and x-2 are negative: $x^2+ |x- 1|+ |x- 2|= x^2- (x- 1)- (x- 2)= x^2- 2x+ 3$.  The derivative is $2x- 2$.
For $1< x\le 3$ x-1 is positive but x-2 is still negative:$x^2+ |x- 1|+ |x- 2|= x^2+ (x- 1)- (x- 2)= x^2+ 10$.  The derivative is $2x$.
For $x> 2$ both x-1 and x-2 are positive: $x^2+ |x- 1|+ |x- 2|= x^2+ (x- 1)+ (x- 2)= x^2+ 2x- 3$.  The derivative is $2x+ 2$.
