Finding a formula for a periodic sequence I came across the sequence $1,5,3,1,5,3,1,5,3,...$ when playing around and now I want to find another function such that $$f(1) = 1, f(2) = 5, f(3) = 3$$ and$$ f(x+3) = f(x)$$
How can I find a function that satisfies those conditions?
I've already found $$ f(x) = -(3 + 2x)\mod 6$$ but I believe there is another function in terms of the $cos$ function? However I'm not very familiar with analytic methods.
 A: As the period is $3$, a candidate function is
$$\cos\frac{2\pi x}{3}.$$
But the three corresponding values are $1,-\dfrac12,-\dfrac12$, which are linearly (even affinely) independent of $1,5,3$. Hence no function like
$$a\cos\frac{2\pi x}{3}+b$$ can work.
To obtain a solution, you can introduce a phase shift,
$$a\cos\left(\frac{2\pi x}{3}+\phi\right)+b.$$
We can solve for $\phi$ by eliminating $a,b$:
$$\frac{\cos\left(\dfrac{4\pi}{3}+\phi\right)-\cos\left(\phi\right)}{\cos\left(\dfrac{2\pi}{3}+\phi\right)-\cos\left(\phi\right)}=\frac{3-1}{5-1} $$ and a solution is $\phi=\dfrac\pi6$.
After solving for $a,b$,
$$-\frac4{\sqrt3}\cos\left(\frac{2\pi x}3+\frac\pi6\right)+3.$$

A: There is only one such function, since you have completely specified the values the function must take on. It sounds like rather you are looking for a different expression of the same function?
For instance, the functions $f(x)=\sin(x)^2 + \cos(x)^2$ and $g(x)=1$ are the same function. They have the same value everywhere, though that might not be obvious by looking at them.
One possibility would be
$$f(n)= \frac{4}{\sqrt{3}}\cos(2\pi n/3 + \pi/2)+3$$
(see here). But I don't think that's any more clear/succinct than your definition in terms of modulus. I think the best, most clear way to define this function would be:
$$f(n) = \begin{cases}1 & n \equiv 1 \pmod 3\\5 & n \equiv 2 \pmod 3 \\ 3 & n \equiv 0 \pmod 3 \end{cases}.$$
A: How about $f(n)=3-\dfrac4{\sqrt3}\sin\left(\dfrac{2\pi n}3\right) $?
A: With $g(x)=\sin ( \frac {2\pi x}{3})$ we get the values of $$g(3k+1)=\frac {\sqrt 3}{2}$$, $$g(3k+2)= -\frac {\sqrt 3}{2}$$ and $$g(3k)=0$$
Then we find a polynomial  $f(x)$which transforms $$(\frac { \sqrt 3}{2}, -\frac {\sqrt 3}{2}, 0) \to (1,5,3)$$
We find $$f(x) = 3-\frac {4\sqrt 3}{3}x$$
The composite  function $$f(g(x))=3-\frac {4\sqrt 3}{3}\sin ( \frac {2\pi x}{3})$$ is the answer.     
