Thanks for that answer, heureka.........
could you explain how you derived your final formula?
...so far:
\(\begin{array}{rcll} a_{n}= \left\{ \begin{array}{ll} 2\cdot n-2 = (2\cdot n - 2) + 0\qquad & (\text{n odd})\\ 2\cdot n-3 = (2\cdot n - 2) -1 \qquad & (\text{n even}) \end{array} \right. \end{array} \)
...composite:
\(\begin{array}{rcll} a_n = (2\cdot n - 2) -1 \cdot s \end{array}\)
s is a switch. We need a function for a switch.
if n is even, s is on or equal 1,
and if n is odd, s is off or equal 0.
As the next we see we can switch with \((-1)^n\)
This function does switch beween -1 and 1 if n is odd or if n is even.
\(\begin{array}{lcr} (-1)^{\text{odd number}} &=& -1 \\ (-1)^{\text{even number}} &=& 1 \end{array} \)
We must modify this "switch" function to get our function.
But it is easy to do this.
First step we add 1.
\(\begin{array}{lcr} 1 + (-1)^{\text{odd number}} &=& -1+1 = 0\\ 1 + (-1)^{\text{even number}}&=& 1+1 = 2\\ \end{array} \)
Second step, the number 2 must be number 1, so we divide by 2
\(\begin{array}{lcr} \dfrac{1 + (-1)^{\text{odd number}} } {2} &=& \frac{0}{2} = 0\\\\ \dfrac{1 + (-1)^{\text{even number}} } {2}&=& \frac{2}{2} = 1\\ \end{array}\)
So our switch s is ready:
\(\begin{array}{lrcr} & s &=& \dfrac{1 + (-1)^n } {2} \\ & s &=& \frac12 [~ 1+(-1)^n ~]\\ n & \text{ is odd} & s = 0 \\ n & \text{ is even} & s = 1 \end{array}\)