You should be able to do this with a polynomial $f$. Indeed, first assume that $f(t) = 4At + 2B$ for some constants $A,B$. Then $$\int^3_0 tf(t) dt = \int^3_0 (4At^2 + 2Bt) dt = 36A + 9 B$$ and $$\int^3_0 t^2 f(t) dt = \int^3_0 (4At^3 + 2Bt^2)dt = 81A + 18B.$$ Thus the desired equations read \begin{align*}
a &= (4A + 2B) + (8A + 2B) + 36A + 9B = 48A +13B,\\
b &= 81A + 18B.
\end{align*} You can write this in matrix vector form as $$\begin{pmatrix}
48 & 13 \\ 81 & 18
\end{pmatrix} \begin{pmatrix}A \\ B \end{pmatrix} = \begin{pmatrix}a \\ b \end{pmatrix}.$$ This has a unique solution $\binom A B$ for any $\binom a b$ since the matrix $\left(\begin{smallmatrix}
48 & 13 \\ 81 & 18
\end{smallmatrix}\right)$ is invertible, and thus the corresponding $f(t) = 4At + 2B$ will solve the equation.