Let $N,h,\gamma,\bar x$ be constants and $x_i\in[-1,1],\forall i=\overline{1,N}$. Consider the following problem $$ \min_u J(u^n) \quad\text{subject to}\quad x_i^{n+1} = x_i^n+hu^n $$ where $$ J(u^n) = \frac{1}{2N}\sum_{i=1}^N |x_i^{n+1}-\bar x|^2+h\gamma|u^n| $$
Consider the problem on a single time interval $[t^n,t^{n+1}]$ and plug the expression for $x_i^{n+1}$ inside $J$ $$ J(u^n) = \frac{1}{2N}\sum_i|x_i^n+hu^n-\bar x|^2+h\gamma|u^n| $$ Derive wrt $u$ \begin{align} J'(u^n) &= \frac hN \sum_i (x_i^n+hu^n-\bar x)+h\gamma\,\text{sgn}(u^n) \\ &= \frac 1N \sum_i(x_i^n-\bar x)+hu^n+\gamma\,\text{sgn}(u^n) = 0 \end{align} By posing $J'(u)=0$ we should be able to find the $u$ minimizing $J$, but how can we isolate it if we have both $u$ and $\text{sgn}(u)$ appearing?
I'd say that we have to discuss separately the two cases $u$ positive and $u$ negative, but I am a bit confused about how we can find an expression for $u$, in one of the two cases, if we don't know a priori when $u$ is positive or negative.
I mean, in order to know the sign of $u$, we have to compute the formula for $u$, but in order to compute the formula we have to know the sign of $u$, so it seems like we can't do anything.
$u^n>0$ $$ u^n = \frac {1}{hN} \sum_i(\bar x-x_i^n)-\frac{\gamma}{h} $$ $u^n<0$ $$ u^n = \frac {1}{hN} \sum_i(\bar x-x_i^n)+\frac{\gamma}{h} $$ Since all values on the rhs are known, I think we have to compute both formulas, one of the two will (I hope) contradict the corresponding hypothesis on the sign of $u$, hence the other one will be the correct one.