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
[Math] How to find a formula for a periodic sequence
periodic functionssequences-and-series
Related Solutions
We have $$ \frac{4\cos\left(\frac{2\pi k}5\right)+4\cos\left(\frac{4\pi k}5\right)-3}5= \left\{\begin{array}{} -1&\text{if }k\not\equiv0\pmod5\\ +1&\text{if }k\equiv0\pmod5\\ \end{array}\right.\tag{1} $$
Explanation
The roots of $z^5-1$ are $z=e^{2\pi ik/5}$ for $k\in\{0,1,2,3,4\}$. Vieta says that the coefficient of $z^4$ in $z^5-1$ the sum of the roots of $z^5-1$. That is, the sum of the roots is $0$. Taking the real part of the roots yields $$ 1+\cos\left(\frac{2\pi}5\right)+\cos\left(\frac{4\pi}5\right)+\cos\left(\frac{6\pi}5\right)+\cos\left(\frac{8\pi}5\right)=0\tag{2} $$ When $k\not\equiv0\pmod5$, $k$ is invertible $\bmod5$. Therefore, $$ \left(\cos\left(\frac{2\pi k}5\right),\cos\left(\frac{4\pi k}5\right),\cos\left(\frac{6\pi k}5\right),\cos\left(\frac{8\pi k}5\right)\right)\tag{3} $$ is a permutation of $$ \left(\cos\left(\frac{2\pi}5\right),\cos\left(\frac{4\pi}5\right),\cos\left(\frac{6\pi}5\right),\cos\left(\frac{8\pi}5\right)\right)\tag{4} $$ Therefore, $$ 1+\cos\left(\frac{2\pi k}5\right)+\cos\left(\frac{4\pi k}5\right)+\cos\left(\frac{6\pi k}5\right)+\cos\left(\frac{8\pi k}5\right)=0\tag{5} $$ when $k\not\equiv0\pmod5$. When $k\equiv0\pmod5$, $$ 1+\cos\left(\frac{2\pi k}5\right)+\cos\left(\frac{4\pi k}5\right)+\cos\left(\frac{6\pi k}5\right)+\cos\left(\frac{8\pi k}5\right)=5\tag{6} $$ Since $\cos(x)$ is an even function with period $2\pi$, $(5)$ and $(6)$ become $$ 1+2\cos\left(\frac{2\pi k}5\right)+2\cos\left(\frac{4\pi k}5\right) =\left\{\begin{array}{} 0&\text{if }k\not\equiv0\pmod5\\ 5&\text{if }k\equiv0\pmod5\\ \end{array}\right.\tag{7} $$ Equation $(1)$ is simply a scaled and translated version of $(7)$.
The extrema occur at the roots of
$$\sin(x)+x\cos(x)=0,$$ or $$\tan x=-x.$$
As the tangent has vertical asymptotes at $x=\left(n+\frac12\right)\pi$, the solutions are close to these values. More precisely, $x\approx\left(2n+\frac12\right)\pi$ in the positives.
Now using Taylor,
$$\tan x=\frac1{\tan\left(\left(2n+\frac12\right)\pi-x\right)}\approx\frac1{\left(2n+\frac12\right)\pi-x}$$
giving the quadratic equation
$$x^2-\left(2n+\frac12\right)\pi x-1=0$$ that you solve for $x$.
$$x=\frac{\sqrt{n^2+n+\frac{17}4}+2n+1}4$$
You can improve on this solution by means of one Newton's iteration,
$$x\leftarrow x-\frac{\tan x+x}{\tan^2x+2}.$$
The analytical expression in terms of $n$ is heavy:
$$\frac{\sqrt{n^2+n+\frac{17}4}+2n+1}4-\frac{\tan \dfrac{\sqrt{n^2+n+\frac{17}4}+2n+1}4+\dfrac{\sqrt{n^2+n+\frac{17}4}+2n+1}4}{\tan^2\dfrac{\sqrt{n^2+n+\frac{17}4}+2n+1}4+2}.$$
The first root, corresponding to $n=0$ is $2.056952$, and the improved value $2.027446$. Then $\tan 2.027446=-2.0354865$.
The larger $n$, the better the approximations.
Update:
The last formulas are wrong as the factor $\pi$ was dropped. But the numerical values are correct.
Best Answer
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})}$$