Velvet Star Monitor

Standout celebrity highlights with iconic style.

general

Formula for alternating sequences

Writer Olivia Zamora
$\begingroup$

I am looking for a general formula for alternating sequences. I know that the formula $f(x)=(-1)^x$ gives the sequence $1,-1,1,-1,...$ but I want more a general formula; for example the function $f(a,b,x)$ which returns the series $a,b,a,b,a,b,...$ as $x$ increases.

So for example the function $f(3,5,x)$ returns the series $3,5,3,5,3,5,...$ What would such a function $f(a,b,x)$ be?

$\endgroup$ 2

3 Answers

$\begingroup$

$$\frac{a+b}{2}+(-1)^{n-1}\cdot\frac{a-b}{2}\ \ (n=1,2,\cdots)$$ represents $a,b,a,b,\cdots$.

$\endgroup$ $\begingroup$

$f(a,b,x)=\tfrac12((a+b)-\cos(\pi x)(a-b))$

$\endgroup$ $\begingroup$

How about: $$f(n)=\begin{cases} 3 & n\equiv 1\mod 2 \\ 5 & n\equiv 0 \mod 2\end{cases}$$

This gives $f(n)=3$ for every odd $n$ and $f(n)=5$ for every even $n$.

Edit As pointed out in the comments: $$f(a,b,n)=\begin{cases} a & n\equiv 1 \mod 2 \\ b & n\equiv 0 \mod 2\end{cases}\quad (n=1,2,\dots)$$ will work for arbitrary $a,b\in\mathbb R$. This can be easily generalised to sequences with more than two different numbers: $$f(a,b,c,n)=\begin{cases} a & n\equiv 1 \mod 3 \\ b & n\equiv 2 \mod 3 \\ c & n\equiv 0 \mod 3\end{cases}$$ for a sequence with three different numbers and finally $$f(a_1,a_2,\dots, a_n,n)=\begin{cases} a_1 & n\equiv 1 \mod n \\ \vdots \\ a_n & n\equiv 0 \mod n\end{cases}$$ for $n$ different numbers.

$\endgroup$ 5

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy