# Proving a recurrence in Mathematica

I have

$$j_n=\int_0^1 x^{2n} \sin(\pi x)dx.$$

How do I show that $$j_{n+1}= \frac{1}{\pi^2}(\pi- (2n+1)(2n+2)j_n)\, ?$$

I keep getting a recurring integration by parts and I can't simplify it. Please tell me where I'm going wrong.

-
Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the FAQs! 3) When you see good Q&A, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. ALSO, remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign –  chris Oct 26 '12 at 16:27

Integration by parts gives

$$\int_0^1 x^k \sin(\pi x) dx = \frac{1}{\pi} + \frac{k}{\pi}\int_0^1 x^{k-1} \cos(\pi x) dx$$

and

$$\int_0^1 x^k \cos(\pi x) dx = - \frac{k}{\pi}\int_0^1 x^{k-1} \sin(\pi x) dx.$$

Applying these rules in succession to $j_{n+1}$ immediately gives

$$j_{n+1} = \frac{1}{\pi} - \frac{(2n+1)(2n+2)}{\pi^2} j_n$$

which clearly is equal to the desired formula.

Notice that this works for any real $n \gt -1$ (so that the integrals converge).

Brute-force attempts at integration produce error functions (Erf), Dawson's integrals (DawsonF), or generalized hypergeometric functions (HypergeometricPFQ), and these do not readily simplify. Let's try something more elementary.

Having seen that the mathematical solution above requires two integrations by parts, we ought to be interested in the second derivative of $x^{2n+2}\sin(\pi x)$:

D[x^(2 n + 2) Sin[Pi x], {x, 2}]


$(2 n+1) (2 n+2) x^{2 n} \sin (\pi x)-\pi ^2 x^{2 n+2} \sin (\pi x) + \color{Red}{2 \pi (2 n+2) x^{2 n+1} \cos (\pi x)}$

The first two terms are exactly what we would be integrating when evaluating $(2n+1)(2n+2)j_{n} - \pi^2 j_{n+1}$ in order to check the equality we're trying to prove. The last term is a problem: how to make it go away? Well, still motivated by integrations by parts, we ought to examine a similar derivative,

D[x^(2 n + 1) Sin[Pi x], x]


$(2 n+1) x^{2 n} \sin (\pi x) + \color{Red}{\pi x^{2 n+1} \cos (\pi x)}$

The second term is a constant multiple of what we're trying to get rid of and the first one is not worrisome: it's proportional to the integrand for $j_n$. So, an appropriate linear combination of these two derivatives ought to clear things up a bit:

Expand[D[x^(2 n + 2) Sin[Pi x], {x, 2}] - 2 (2 + 2 n) D[x^(2 n + 1) Sin[Pi x], x] , x]


$-(2 n+1) (2 n+2) x^{2 n} \sin (\pi x)-\pi ^2 x^{2 n+2} \sin (\pi x)$

This can be stated in reverse: the indefinite integral of the result is what we differentiated, so let's just take one less derivative to find out what it is!

D[x^(2 n + 2) Sin[Pi x], x] - 2 (2 + 2 n) x^(2 n + 1) Sin[Pi x]


$\pi x^{2 n+2} \cos (\pi x)-(2 n+2) x^{2 n+1} \sin (\pi x)$

By the Fundamental Theorem of Calculus, we can find $-(2n+1)(2n+2)j_n - \pi^2 j_{n+1}$ by evaluating this antiderivative at the endpoints $0$ and $1$:

FullSimplify[% /. {x -> #} & /@ {0, 1} // Differences, Assumptions -> n > -1]


$\{-\pi \}$

That is, these Mathematica manipulations have demonstrated that

\eqalign{ -(2n+1)(2n+2)j_n - \pi^2 j_{n+1} &= \int_0^1 \left(-(2n+1)(2n+2)x^{2n}\sin{\pi x} - \pi^2 x^{2n+2}\sin(\pi x)\right) dx \\ &= \left(\pi x^{2 n+2} \cos (\pi x)-(2 n+2) x^{2 n+1} \sin (\pi x)\right)\mid_0^1 \\ &= -\pi. }

This obviously is algebraically equivalent to the desired result. But in the process we have obtained an indefinite integral for the integrands associated with this linear combination of $j_n$ and $j_{n+1}$.

-

I have more (mathematica) questions than answers.

Let us define

J[n_] := Integrate[ x^(2 n)  Sin[Pi x], {x, 0, 1}]

(* (Pi*HypergeometricPFQ[{1 + n}, {3/2, 2 + n}, -Pi^2/4])/(2 + 2*n) *)


and

Clear[JJ];
JJ[n_] :=  JJ[n]=1/Pi^2 (Pi - (2 n ) (2 n -1) JJ[n - 1]) // Simplify
JJ[0] = J[0];


We have

 Table[J[n] - JJ[n], {n, 0, 6}] // Simplify

(* {0,0,0,0,0,0,0} *)


which suggests the recursion is 'likely'

(Thanks to KennyColnago for pointing out an offset in the recursion)

My question would be: why

  Table[J[n],{n,0,4}]//FindSequenceFunction


does not provide the recursion? And I don't understand why

 Clear[j];  eqn = j[n] == b j[n - 1] + c /.
Solve[Table[J[n] == b J[n - 1] + c, {n, 1, 2}] // Simplify, {b,c}][[1]]

Table[eqn /. j -> J, {n, 1, 3}] // Simplify


produces

(* {True,True,False} *)

-
There is an index problem. Your definition of JJ[n_] has JJ[n-1] on the right-hand side, and so should have the $n$ there as $n-1$. That is, JJ[n_]:= 1/Pi^2 (Pi - (2 (n-1) + 2) (2 (n-1) + 1) JJ[n - 1]). Thus I believe the recursion is correct. –  KennyColnago Oct 24 '12 at 18:27
@KennyColnago oops!!! –  chris Oct 24 '12 at 18:30
Why are you asking a question as an answer? You should ask a new question instead –  rm -rf Oct 24 '12 at 21:07
@rm-rf I did provide a partial answer; I wanted to have a clean proof and, having been told about FindSequenceFunction not long ago on this mathematica.stackexchange.com/questions/11042/… I was expecting it to work. –  chris Oct 25 '12 at 7:39

Quite a manual process :

Solve the indefinite integral, then calculate the definite one :

indefInt[n_, x_] = Simplify[Integrate[x^(2 (n)) Sin[Pi x], x],
Assumptions -> {0 <= x <= 1, n \[Element] Integers}];

int[n_] = Assuming[n \[Element] Integers,
Limit[indefInt[n, x], x -> 1, Direction -> +1] -
Limit[indefInt[n, x], x -> 0, Direction -> -1]];


Now define an identity regarding the incomplete Gamma function :

recursion = Gamma[n_, z_] -> (n - 1) Gamma[n - 1, z] + z^(n - 1) Exp[-z];


Finally put everything together :

en = FullSimplify[int[n] /. recursion, Assumptions -> {n \[Element] Integers, n > 0}] ;

enp1 = FullSimplify[int[n + 1] /. recursion /. recursion /. recursion,
Assumptions -> {n \[Element] Integers, n > 0}];

FullSimplify[enp1 - 1/Pi^2 (Pi - (2 n + 1) (2 n + 2) en),
Assumptions -> {n \[Element] Integers, n > 0}]

(* 0 *)
`
-
do you know why mma does not provide your closed form as the naive integration solution? Do you know why it does not find the recursion either? –  chris Oct 24 '12 at 19:19
@chris It gives a closed form solution for the integral but it involves hypergeometric functions and I am not aware of similar recursions. –  b.gatessucks Oct 24 '12 at 19:24