Solution (source code)

= Solution

Differentiating the truncated Fourier expansion gives
$$
u_x=\sum_{m=-d}^di\pi m\widehat u_m e^{i\pi mx}.
$$
The $n$th Fourier coefficient of the product $cu_x$ is the <discrete convolution>
$$
i\pi\sum_{m=-d}^dm\widehat c_{n-m}\widehat u_m.
$$
Projecting the advection equation onto modes $|n|\leq d$ therefore gives
$$
\frac{d\widehat u_n}{dt}
=-i\pi\sum_{m=-d}^dm\widehat c_{n-m}\widehat u_m.
$$
Thus
$$
\boxed{\frac{d\widehat{\mathbf u}}{dt}
=i\pi B\widehat{\mathbf u}},
\qquad
\boxed{B_{nm}=-m\widehat c_{n-m}}.
$$
Equivalently, if
$$
C_{nm}=\widehat c_{n-m},
\qquad
D=\operatorname{diag}(-d,-d+1,\ldots,d),
$$
then
$$
\boxed{B=-CD}.
$$
This is the <Fourier spectral method for variable-coefficient advection>.