What function would do this

47 Views Asked by At

I need a function $f(n)$ that if $n$ is odd it returns $-1$, but if it is even it returns $1$. Is there a function like this? If so what is it? Also I would appreciate if it is not a trig function (Ahem $f(n) = \cos(n\pi)$).

3

There are 3 best solutions below

0
On BEST ANSWER

What you have defined is already a function, but I assume what you want is an elementary expression for it. Try $$(-1)^{n}$$

0
On

Consider $f\colon\mathbb{Z}\to\mathbb{Z}$ defined by $$ f(n)= \begin{cases} -1 &\text{if} & n=2k+1, k\in\mathbb{Z},\\ 1 &\text{if} & n=2k, k\in\mathbb{Z}. \end{cases} $$

0
On

I think this works as well.
$$f(n):= (-1)^n$$