# How do you find an equation for this function that is not recursive?

## $f \left(n\right) = - 2 f \left(n - 1\right) + {\left(- 1\right)}^{n} \left(n - 1\right)$ Thanks in advance!

Mar 30, 2018

$f \left(n\right) = {\left(- 1\right)}^{n} \left({2}^{n} \left(k + 1\right) - n - 1\right)$

#### Explanation:

I will assume that this is a function of integers, since otherwise there are many possible variations.

Given:

$f \left(n\right) = - 2 f \left(n - 1\right) + {\left(- 1\right)}^{n} \left(n - 1\right)$

Let:

$g \left(n\right) = {\left(- 1\right)}^{n} f \left(n\right)$

Then:

$g \left(n\right) = {\left(- 1\right)}^{n} f \left(n\right)$

$\textcolor{w h i t e}{g \left(n\right)} = {\left(- 1\right)}^{n} \left(- 2 f \left(n - 1\right) + {\left(- 1\right)}^{n} \left(n - 1\right)\right)$

$\textcolor{w h i t e}{g \left(n\right)} = {\left(- 1\right)}^{n} \left(- 2 {\left(- 1\right)}^{n - 1} g \left(n - 1\right) + {\left(- 1\right)}^{n} \left(n - 1\right)\right)$

$\textcolor{w h i t e}{g \left(n\right)} = 2 g \left(n - 1\right) + \left(n - 1\right)$

Let:

$k = g \left(0\right)$

Then $g \left(0\right)$, $g \left(1\right)$, $g \left(2\right)$,... form a sequence:

$k$, $2 k$, $4 k + 1$, $8 k + 4$, $16 k + 11$, $32 k + 26$,...

Putting $k = 0$, this sequence becomes:

$0 , 0 , 1 , 4 , 11 , 26 , \ldots$

This has differences:

$0 , 1 , 3 , 7 , 15 , \ldots$

recognisable as ${2}^{n} - 1$

Let us compare the previous sequence with ${2}^{n}$:

$1 , 2 , 4 , 8 , 16 , 32 , \ldots$

A matching formula is:

${2}^{n} - n - 1$

So the general formula for $g \left(n\right)$ can be written:

$g \left(n\right) = {2}^{n} \left(k + 1\right) - n - 1$

So the formula for $f \left(n\right)$ can be written:

$f \left(n\right) = {\left(- 1\right)}^{n} \left({2}^{n} \left(k + 1\right) - n - 1\right)$

Mar 31, 2018

See below.

#### Explanation:

This is a linear difference equation. It can be solved as

$f \left(n\right) = {f}_{h} \left(n\right) + {f}_{p} \left(n\right)$ with

${f}_{h} \left(n\right) + 2 {f}_{h} \left(n - 1\right) = 0$
${f}_{p} \left(n\right) + 2 {f}_{p} \left(n - 1\right) = {\left(- 1\right)}^{n} \left(n - 1\right)$

To solve ${f}_{h} \left(n\right)$ we make

$f \left(n\right) = {a}^{n}$ and after substitution

${a}^{n} + 2 {a}^{n - 1} = 0 \Rightarrow a = - 2 \Rightarrow {f}_{h} \left(n\right) = {\left(- 1\right)}^{n} {2}^{n}$

for the particular we make ${f}_{p} \left(n\right) = {c}_{n} {\left(- 1\right)}^{n} {2}^{n}$ and after substitution

${c}_{n} {\left(- 1\right)}^{n} {2}^{n} + 2 {c}_{n - 1} {\left(- 1\right)}^{n - 1} {2}^{n - 1} = {\left(- 1\right)}^{n} \left(n - 1\right)$ or

${c}_{n} - {c}_{n - 1} = \left(n - 1\right) {2}^{-} n$ or

${c}_{n} = {c}_{n - 1} + \left(n - 1\right) {2}^{-} n$ or

${c}_{n} = {c}_{0} + {\sum}_{k = 1}^{n} \left(k - 1\right) {2}^{-} k$

and finally

$f \left(n\right) = \left({c}_{0} + {\sum}_{k = 1}^{n} \left(k - 1\right) {2}^{-} k\right) {\left(- 1\right)}^{n} {2}^{n}$

This formulation can be simplified a lot but we let this task to the reader.

NOTE

${\sum}_{k = 1}^{n} \left(k - 1\right) {x}^{k} = {x}^{2} {\sum}_{k = 0}^{n - 1} {x}^{k} = {x}^{2} \frac{d}{\mathrm{dx}} \left(\frac{{x}^{n} - 1}{x - 1}\right)$ then

${\sum}_{k = 1}^{n} \left(k - 1\right) {x}^{k} = \frac{x \left(x + \left(n \left(x - 1\right) - x\right) {x}^{n}\right)}{x - 1} ^ 2$

now making $x = {2}^{-} 1$ we obtain

${\sum}_{k = 1}^{n} \left(k - 1\right) {2}^{-} k = 1 - \left(n + 1\right) {2}^{-} n$

Apr 1, 2018

$f \left(n\right) = {\left(- 1\right)}^{n} \left[{2}^{n} \left(f \left(0\right) + 1\right) - n - 1\right]$

#### Explanation:

The equation

$f \left(n\right) = - 2 f \left(n - 1\right) + {\left(- 1\right)}^{n} \left(n - 1\right)$

can be rewritten in the form

$f \left(n\right) + {\left(- 1\right)}^{n} \left(n + 1\right) = - 2 f \left(n - 1\right) + {\left(- 1\right)}^{n} \left\{\left(n - 1\right) + \left(n + 1\right)\right\}$
$q \quad q \quad = - 2 \left(f \left(n - 1\right) + {\left(- 1\right)}^{n - 1} n\right)$

This shows that the function, $F \left(n\right)$, defined by

$F \left(n\right) \equiv f \left(n\right) + {\left(- 1\right)}^{n} \left(n + 1\right)$

obeys

$F \left(n\right) = - 2 F \left(n - 1\right)$

The obvious solution for this equation is

$F \left(n\right) = {\left(- 2\right)}^{n} F \left(0\right)$

Since $F \left(0\right) = f \left(0\right) + 1$, we have

$F \left(n\right) \equiv f \left(n\right) + {\left(- 1\right)}^{n} \left(n + 1\right) = {\left(- 2\right)}^{n} \left(f \left(0\right) + 1\right)$

and so

$f \left(n\right) = {\left(- 2\right)}^{n} \left(f \left(0\right) + 1\right) - {\left(- 1\right)}^{n} \left(n + 1\right)$
$q \quad = {\left(- 1\right)}^{n} \left[{2}^{n} \left(f \left(0\right) + 1\right) - n - 1\right]$