I am trying to find the gradient of the following optimization problem and then add to objective, but I got some trouble in computing. Could you please help me?

Assume that we have an optimization problem with the objective $$ \min_{w} \sum_{j}^{n}\sum_{i}^{n_t} \left( \hat{T}_j(t_i) - T(t_i, w) \right)^2 + c . \| w \|_1 $$ where $w \in [ 0, 1 ]$ and $c$ is a constant. $\hat{T}_j(t_i)$ and $T(t_i, w)$ are computed using heat equation with initial value: $$\begin{array}{rlll} T_t(t,x) + L_w . T(t,x) & = & F(t,x) , \\ % T(0,t) & = & T(1,t) = 0 & \\ T(x,0) & = & T_0 . \end{array}$$ $F(t,x)$ is given and $L_w$ is the weighted Laplacian of a graph $G=(V,E)$ and $$L_w(G):= \sum_{ij \in E} w_{ij} E_{ij}$$ It should be added that $\hat{T}_j(t_i)$ is obtained from above equations by fixing an arbitrary $w$, but for $T(t_i, w)$ is changing in each time step.