Solution (source code)

= Solution

The <total derivative> follows the curve $x\mapsto(x,y(x))$, so the <chain rule> gives
$$
\boxed{\frac{du}{dx}=\left(\frac{\partial u}{\partial x}\right)_y+
\left(\frac{\partial u}{\partial y}\right)_x\frac{dy}{dx}.}
$$
For the stated functions, $u_x=6x$, $u_y=2y$ and $y'=\cos x$, hence
$$
\boxed{\frac{du}{dx}=6x+2\sin x\cos x=6x+\sin2x.}
$$
Direct differentiation of $u(x,\sin x)=3x^2+\sin^2x$ gives the same result.