3
$\begingroup$

I'd like to get help with achieving periodicity.

Let's say I have a positive power $n$ of $2$:

$$2^n$$

I need to alter the sign of $n$ periodically according to the next behavior:

With integers from 0 to 5 sign should be +, with integers 6 and 11 sign should be -. Integers 12 to 17 should map to +, 18 ... 23 to -, and so on.

How do I alter the sign of the $n$ according to my definition? Should it be done with mod, sin, ???

Afterthought

This can probably be thought as periodicity of six rather than complex oscillations between 5, 6 and 12.

$\endgroup$
2
$\begingroup$

The simplest way is using floor function: $$(-1)^{\lfloor\frac n6\rfloor}2^n$$

Trigonometric functons have a problem: a function like $\lfloor\sin \frac {\pi n}6 \rfloor$ will yield $0$ when $n$ is a multiple of $6$.

$\endgroup$
1
  • $\begingroup$ $(-1)^{\lfloor\frac{n}{6}\rfloor}$ seems to do the job. And it is doable with mod notation too. $\endgroup$ – MarkokraM Sep 2 '18 at 15:04
3
$\begingroup$

Any time you need signs to alternate according to a fixed period, your first thought should be the powers of $-1$.

With $n$ running through the integers, we have $$(-1)^n = -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, \ldots$$ For your purpose you just need to slow it down. You need $n$ to go through a sequence like this one: 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, etc.

Simply dividing $n$ by 6 gives us (approximately) 0.17, 0.33, 0.5, 0.67, 0.83, 1, 1.17, 1.33, 1.5, 1.67, 1.83, 2, 2.17, 2.33, 2.5, 2.67, etc.

Here's an interesting digression: if $\alpha$ is a real number but not an integer, $(-1)^\alpha$ is imaginary or complex.

Anyway, the sequence of 0.17, 0.33, 0.5, 0.67 is would be perfect for what you need except for all those digits after the decimal point. So chuck them with the floor function.

Thus: $$(-1)^{\lfloor \frac{n}{6} \rfloor}.$$

$\endgroup$

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.