3
$\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
  • $\begingroup$ You seem to be using "function" in the colloquial sense of a formula. Hirshy's answer uses "function" in the technical mathematical sense of a relation. $\endgroup$
    – joriki
    Aug 6 '15 at 19:25
  • 1
    $\begingroup$ $\tfrac12((a+b)-(-1)^n(a-b))$ $\endgroup$
    – g.kov
    Aug 6 '15 at 19:27
7
$\begingroup$

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

$\endgroup$
3
$\begingroup$

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

$\endgroup$
0
$\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
  • $\begingroup$ They mean for 3 and 5 to be arguments to the function, such that $f(1,2,x) = 1, 2, 1, 2, 1, 2$ and $f(9,11,x) = 9, 11, 9, 11, 9, 11$. $\endgroup$
    – Axoren
    Aug 6 '15 at 19:28
  • $\begingroup$ @Axoren one can easily write this as $$f(3,5,n)=\begin{cases} 3 & n\equiv 1\mod 2 \\ 5 & n\equiv 0 \mod 2\end{cases}$$ if the numbers $3$ and $5$ should be included as arguments. $\endgroup$
    – Hirshy
    Aug 6 '15 at 19:31
  • $\begingroup$ Do you mean the following? $$f(a,b,n)=\begin{cases} a & n\equiv 1\mod 2 \\ b & n\equiv 0 \mod 2\end{cases}$$ Edit: Just saw your edit, that's what you meant. $\endgroup$
    – Axoren
    Aug 6 '15 at 19:32
  • 1
    $\begingroup$ dang I just realised what you meant; I was to focused on the sequence given by Hector, that I didn't think this all the way through. $\endgroup$
    – Hirshy
    Aug 6 '15 at 19:34
  • $\begingroup$ @Axoren thank you for pointing that out, I edited my answer for a more useful/correct function. $\endgroup$
    – Hirshy
    Aug 6 '15 at 19:39

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.