Integration by parts for specific problem

62 Views Asked by At

I am trying to do the following integral:

$$\int_0^L x \sin((m+\frac{1}{2})\frac {\pi x} {L}) dx$$

Where $m$ is an integer, $L$ a constant and $x$ a variable using integration by parts. I have first removed the bounds to make it an indefinite integral and set:

$$u = x,$$ $$du=dx,$$ $$dv = \sin((m+\frac 1 2)\frac {\pi x} {L})\,dx$$ and $$v = \frac{-L}{(m+\frac 1 2)\pi}\cos((m+ \frac 1 2)\frac {\pi x} {L})$$

assuming $\int u \,dv = uv-\int v \,du$

$$\int x \sin((m+\frac{1}{2})\frac {\pi x} {L}) \,dx=\frac{-Lx}{(m+\frac 1 2)\pi}\cos((m+ \frac 1 2)\frac {\pi x} {L})+ \int \frac{-L}{(m+\frac 1 2)\pi}\cos((m+ \frac 1 2)\frac {\pi x} {L})\,dx$$

The integral on the right hand side easily solved by substitution: $$\frac{-Lx}{(m+\frac 1 2)\pi}\cos((m+ \frac 1 2)\frac {\pi x} {L})+ \frac{L^2}{(m+\frac 1 2)^2\pi^2}\sin((m+ \frac 1 2)\frac {\pi x} {L})$$

Now reverting to the definite integral:

$$\biggl[\frac{-Lx}{(m+\frac 1 2)\pi}\cos((m+ \frac 1 2)\frac {\pi x} {L})+ \frac{L^2}{(m+\frac 1 2)^2\pi^2}\sin((m+ \frac 1 2)\frac {\pi x} {L})\biggr]^L_0$$

Which simplifies to:

$$\biggl[\frac{-L^2}{(m+\frac 1 2)\pi}\cos((m+ \frac 1 2)\frac {\pi L} {L})+ \frac{L^2}{(m+\frac 1 2)^2\pi^2}\sin((m+ \frac 1 2)\frac {\pi L} {L})\biggr]-\biggl[\frac{-L(0)}{(m+\frac 1 2)\pi}\cos((m+ \frac 1 2)\frac {\pi (0)} {L})+ \frac{L^2}{(m+\frac 1 2)^2\pi^2}\sin((m+ \frac 1 2)\frac {\pi (0)} {L})\biggr]$$

The expression in the second square bracket is $0$. The expression in the first square bracket simplifies to:

$$\biggl[\frac{-L^2}{(m+\frac 1 2)\pi}\cos((m+ \frac 1 2)\pi)+ \frac{L^2}{(m+\frac 1 2)^2\pi^2}\sin((m+ \frac 1 2)\pi)\biggr]$$

The first term in the above expression is equal to $0$ for any integer $m$ and thus we are left with:

$$\int x \sin((m+\frac{1}{2})\frac {\pi x} {L}) \,dx = \frac{L^2}{(m+\frac 1 2)^2\pi^2}\sin((m+ \frac 1 2)\pi)$$

I have run this integral through a symbolic software package (SymPy) which output the following result:

$$\begin{cases}0,&m=0\\-\frac{L^2}{\pi m} \cos(\pi m) + \frac{L^2}{\pi^2 m^2}\sin(\pi m), &\text{otherwise}\end{cases}$$

I am not happy with this because plugging in $m = 5$ and $L=2$ yields a result of $0.255$ for the SymPy result and $-0.0134$ for my hand result. Which is right and if they are both right how come there are two different results? It seems to me only one can exist for this integral.