Suppose we have toy daily temperate data and we want to fit a model.
A reasonable thing to do is fitting a periodic model with Fourier basis
$$ f(x)=\beta_0+\beta_1 \cos(2\pi x/24)+\beta_2 \sin(2\pi x/24) $$
So the Fourier basis expansion of data matrix $\mathbf X$ is
$$ \begin{bmatrix} 1&\cos 0 & \sin 0 \\ 1&\cos \frac \pi 4 & \sin \frac \pi 4 \\ \cdots & \cdots & \cdots\\ 1&\cos \frac {7\pi} 4 &\sin \frac {7\pi} 4 \end{bmatrix} $$
On the other hand, suppose I do not know Fourier expansion and only know polynomial fit. So I fit data with a third order polynomial, where
$$ f(x)=\beta_0+\beta_1 x+\beta_2 x^2 +\beta_3 x^3 $$
The polynomial basis expansion of data matrix $\mathbf X$ is (for demo purpose, I am not using orthogonal polynomial which will be ill conditioned in real world problems.)
$$ \begin{bmatrix} 1&\ 0 & 0 & 0 \\ 1& 3 & 3^2 & 3^3\\ & \cdots\\ 1&\ 21 &21^2 & 21^3\end{bmatrix} $$
The two fits are shown below, and they are "similar". My question is, what's wrong with the polynomial fit on periodical data? In this case we do not have the extrapolation and the time should always be $[0,23]$
d = data.frame(t=c(0,3,6,9,12,15,18,21),
temp=c(-2.2,-2.8,-6.1,-3.9,0,1.1,-0.6,-1.1))
X=cbind(1,cos(2*pi*d$t/24),sin(2*pi*d$t/24))
coeff = solve(t(X) %*% X, t(X) %*% d$temp)
X2=cbind(1,d$t, d$t^2, d$t^3)
coeff_2 = solve(t(X2) %*% X2, t(X2) %*% d$temp)
plot(d$t,d$temp,type='b')
d_new = seq(0,24,0.1)
X=cbind(1,cos(2*pi*d_new/24),sin(2*pi*d_new/24))
X2=cbind(1,d_new, d_new^2, d_new^3)
lines(d_new,X %*% coeff, type='l',col='red')
lines(d_new,X2 %*% coeff_2, type='l', col='blue')