Optimal distributed control of linear parabolic equations by spectral decomposition