How to find a formula for a periodic sequence? I would like to find the formula for a periodic sequence such as 4, 1, 1/4, 1/4, 1, 4... with a period of 6
 A: You want, presumably, $f(x)$ such that $f(1)=4,f(2)=1...$ and so on, with a period of $6$, so that there will be lines of symmetry at $x=\frac 12,\frac 72$ and so on.
This can be modelled by a displaced cosine curve which includes a similarly periodic adjustment factor which "warps" the cosine wave to fit the point $(2,1)$.
Therefore we can try $$f(x)=\frac{\mu\cos(\frac{\pi x}{3}-\frac{\pi}{6})+\nu}{\lambda+\cos(\frac{\pi x}{3}-\frac{\pi}{6})}$$
On substituting for $x=1,2,3$ we get three equations and can identify the contants $\lambda,\mu,\nu$, and obtain
$$f(x)=\frac{5\sqrt{3}+6\cos(\frac{\pi x}{3}-\frac{\pi}{6})}{5\sqrt{3}-6\cos(\frac{\pi x}{3}-\frac{\pi}{6})}$$
A: 
Hint: The $r$-th roots of unity $\omega_j=\exp\left(\frac{2\pi ij}{r}\right), 0\leq j<r$ have the nice property to filter elements. For $r>0$ we obtain
  \begin{align*}
\frac{1}{r}\sum_{j=0}^{r-1}\exp\left(\frac{2\pi ij n}{r}\right)=
\begin{cases}
1&\qquad r\mid n\\
0& \qquad otherwise
\end{cases}
\end{align*}
  Therefore the sequence
  \begin{align*}
\left(\frac{1}{6}\sum_{j=0}^5\exp\left(\frac{2\pi ijn}{6}\right)\right)_{n=0}^{\infty}
=(1,0,0,0,0,0,1,0,0,0,0,0,1,\ldots)\tag{1}
\end{align*}
  generates a $1$ at each $6$-th position and $0$ otherwise and multiplication with $4$ gives a sequence with $4$ at each $6$-th position and $0$ otherwise.
Appropriately shifting of (1) can be used to generate a $1$ on each $6$-th position shifted by $k$ positions with $0\leq k < 6$. Multiplication with $4,1$ and $\frac{1}{4}$ and adding all these terms provides the wanted sequence.

Hint: Some instructive examples can be found in H.S. Wilf's book generatingfunctionology, (2.4.5) to (2.4.9).
A: 
Here    is      a    variation    which  utilizes  the  special structure    of   the sequence.
The sequence can be written as
  \begin{align*}
(a_n)_{n\geq 0}&=\left(4,1,\frac{1}{4},\frac{1}{4},1,4,4,1,\frac{1}{4},\ldots\right)\\
&=\left(4^1,4^0,4^{-1},4^{-1},4^0,4^1,4^1,4^0,4^{-1},\ldots\right)
\end{align*}

Since 
\begin{align*}
\left(1-\left(n \text{ mod} (3)\right)\right)_{n\geq 0}=(1,0,-1,1,0,-1,1,0,-1,\ldots)
\end{align*}
and
\begin{align*}
\left((-1)^{\left\lfloor\frac{n}{3}\right\rfloor}\right)_{n\geq 0}=(1,1,1,-1,-1,-1,1,1,1,\ldots)
\end{align*}
we obtain
\begin{align*}
\left((-1)^{\left\lfloor\frac{n}{3}\right\rfloor}\left(1-\left(n \text{ mod} (3)\right)\right)\right)_{n\geq 0}
=(1,0,-1,-1,0,1,1,0,-1,\ldots)
\end{align*}

We conclude the sequence $(a_n)_{n\geq 0}$ can be written as
  \begin{align*}
(a_n)_{n\geq 0}=\left(4^{(-1)^{\left\lfloor\frac{n}{3}\right\rfloor}\left(1-\left(n \text{ mod} (3)\right)\right)}\right)_{n\geq 0}
\end{align*}

