I was using Mathematica 11.2 on windows 7, to verify my hand solution to the following 1D wave PDE.

Mathematica gives the solution, which is almost correct, but the sum it gives is over all $n$, where the result should be over odd $n$ only.

I am posting this question to ask if this is a bug or not. Using the result as given by Mathematica will not even run, since it gives division by zero.

Will show my hand solution and show that Mathematica's output will be correct, if the series it gives, it summed over odd n only. Then it will match my hand solution.

Here is the PDE to solve

Solve wave PDE $u_{tt}=4u_{xx}$ on bounded domain $0<x<\pi,t>0$ with boundary conditions $u\left( 0,t\right) =0,u\left( \pi,t\right) =0$ and initial conditions $u\left( x,0\right) =\sin^{2}x,u_{t}\left( x,0\right) =0$.

This is the result from hand solution:

$$ u\left( x,t\right) =\frac{-8}{\pi}\sum_{n=1,3,5,\cdots}^{\infty}\frac {1}{n^{3}-4n}\cos\left( 2nt\right) \sin\left( nx\right) $$

Here is Mathematica's result

pde  = D[u[x,t],{t,2}]==4D[u[x,t],{x,2}];
ic   = {Derivative[0,1][u][x,0]==0,u[x,0]==Sin[x]^2}
bc   = {u[0,t]==0,u[Pi,t]==0};
sol  = DSolve[{pde,bc,ic},u[x,t],{x,t}];
sol  = sol/.K[1]->n  (*n looks better than K[1] for index *)

Mathematica graphics

One can see that Mathematica result matches hand solution when $n$ is odd $1,3,5,\dots$. When $n$ is even, for $n=2$, there will be a division by zero above. So $n=2$ can't be there. And all even $n$ should not be there.

So I think Mathematica solution above is wrong! Do you agree? If so, is there a way to fix this and Make it generate the correct solution?

hand solution

Putting the PDE in standard form $u_{tt}=a^{2}u_{xx}$ shows that $a=2$

Applying separation of variables gives \begin{align*} T^{\prime\prime}X & =4X^{\prime\prime}T\\ \frac{1}{4}\frac{T^{\prime\prime}}{T} & =\frac{X^{\prime\prime}}{X}=-\lambda \end{align*} The eigenvalue ODE\ is $X^{\prime\prime}+\lambda X=0$ with $X\left( 0\right) =0,X\left( \pi\right) =0$. This has eigenfunctions $\Phi_{n}\left( x\right) =\sin\left( \sqrt{\lambda_{n}}x\right) $ with $\lambda_{n}=n^{2}$ where $n=1,2,3,\cdots$. The time ODE becomes $$ T^{\prime\prime}+4\lambda_{n}T=0 $$ Since $\lambda_{n}>0$, the solution is \begin{align*} T\left( t\right) & =A_{n}\cos\left( \sqrt{4\lambda_{n}}t\right) +B_{n}\sin\left( \sqrt{4\lambda_{n}}t\right) \\ & =A_{n}\cos\left( 2nt\right) +B_{n}\sin\left( 2nt\right) \end{align*} And $$ T^{\prime}=-2nA_{n}\sin\left( 2nt\right) +2nB_{n}\cos\left( 2nt\right) $$ Since $T^{\prime}\left( 0\right) =0$, then the above implies that $B_{n}=0$. Therefore the solution simplifies to $$ T_{n}\left( t\right) =A_{n}\cos\left( 2nt\right) $$ And the fundamental solution becomes \begin{align*} u_{n} & =T_{n}X_{n}\\ & =c_{n}\cos\left( 2nt\right) \sin\left( nx\right) \end{align*} Hence by superposition, the general solution is $$ u\left( x,t\right) =\sum_{n=1}^{\infty}c_{n}\cos\left( 2nt\right) \sin\left( nx\right) $$ At $t=0$, $u\left( x,0\right) =\sin^{2}x$, therefore the above becomes $$ \sin^{2}x=\sum_{n=1}^{\infty}c_{n}\sin\left( nx\right) $$ Applying orthogonality gives \begin{align} \int_{0}^{\pi}\sin^{2}x\sin\left( nx\right) dx & =c_{n}\frac{\pi}{2} \tag{1}\\ \int_{0}^{\pi}\left( \frac{1}{2}-\frac{1}{2}\cos2x\right) \sin\left( nx\right) dx & =c_{n}\frac{\pi}{2}\nonumber \end{align} To evaluate $\int_{0}^{\pi}\left( \frac{1}{2}-\frac{1}{2}\cos2x\right) \sin\left( nx\right) dx$, it is split into $\int_{0}^{\pi}\left( \frac {1}{2}\sin\left( nx\right) -\frac{1}{2}\cos2x\sin\left( nx\right) \right) dx$. But the first part is \begin{align*} \int_{0}^{\pi}\frac{1}{2}\sin\left( nx\right) dx & =-\frac{1}{2n}\left( \cos\left( nx\right) \right) _{0}^{\pi}\\ & =-\frac{1}{2n}\left( \cos\left( n\pi\right) -1\right) \end{align*} For even $n=2,4,\cdots$ the above vanishes. For odd $n=1,3,5,\cdots$ the above becomes $$ \int_{0}^{\pi}\frac{1}{2}\sin\left( nx\right) dx=\frac{1}{n} $$ Now the second integral is evaluated $$ \int_{0}^{\pi}-\frac{1}{2}\cos2x\sin\left( nx\right) dx=-\frac{1}{2}\int _{0}^{\pi}\cos2x\sin\left( nx\right) dx $$ Using $\int_{0}^{\pi}\sin\left( px\right) \cos\left( qx\right) dx=-\frac{\cos\left( p-q\right) x}{2\left( p-q\right) }-\frac{\cos\left( p+q\right) x}{2\left( p+q\right) }$, then the above becomes, where $p=n,q=2$

\begin{align*} -\frac{1}{2}\int_{0}^{\pi}\sin\left( nx\right) \cos2xdx & =-\frac{1} {2}\left( -\frac{\cos\left( n-2\right) x}{2\left( n-2\right) }-\frac {\cos\left( n+2\right) x}{2\left( n+2\right) }\right) _{0}^{\pi}\\ & =\frac{1}{2}\left( \frac{\cos\left( n-2\right) x}{2\left( n-2\right) }+\frac{\cos\left( n+2\right) x}{2\left( n+2\right) }\right) _{0}^{\pi }\\ & =\frac{1}{2}\left( \frac{\cos\left( n-2\right) \pi}{2\left( n-2\right) }+\frac{\cos\left( n+2\right) \pi}{2\left( n+2\right) }-\frac{1}{2\left( n-2\right) }-\frac{1}{2\left( n+2\right) }\right) \end{align*} For even $n=2,4,\cdots$ the above vanishes, since it becomes $\frac{1} {2}\left( \frac{1}{2\left( n-2\right) }+\frac{1}{2\left( n+2\right) }-\frac{1}{2\left( n-2\right) }-\frac{1}{2\left( n+2\right) }\right) $, and for odd $n=1,3,5,\cdots$, the above becomes \begin{align*} -\frac{1}{2}\int_{0}^{\pi}\sin\left( nx\right) \cos2xdx & =\frac{1} {2}\left( \frac{-1}{2\left( n-2\right) }-\frac{1}{2\left( n+2\right) }-\frac{1}{2\left( n-2\right) }-\frac{1}{2\left( n+2\right) }\right) \\ & =\frac{1}{2}\left( \frac{-2}{2\left( n-2\right) }+\frac{-2}{2\left( n+2\right) }\right) \\ & =\frac{-1}{2\left( n-2\right) }+\frac{-1}{2\left( n+2\right) }\\ & =-\frac{n}{n^{2}-4} \end{align*} Therefore, the final result of integration is \begin{align*} \int_{0}^{\pi}\sin^{2}x\sin\left( nx\right) dx & =\frac{1}{n}-\frac {n}{n^{2}-4}\qquad n=1,3,5,\cdots\\ & =-\frac{4}{n\left( n^{2}-4\right) }\qquad n=1,3,5,\cdots \end{align*} Hence from (1), this results in \begin{align*} c_{n} & =-\frac{2}{\pi}\frac{4}{n\left( n^{2}-4\right) }\\ & =-\frac{8}{\pi n\left( n^{2}-4\right) }\qquad n=1,3,5,\cdots \end{align*} Hence the final solution is $$ u\left( x,t\right) =\frac{-8}{\pi}\sum_{n=1,3,5,\cdots}^{\infty}\frac {1}{n^{3}-4n}\cos\left( 2nt\right) \sin\left( nx\right) $$

  • $\begingroup$ Maple 2017.3 give the same answer what gives MMA 11.2 or MMA 11.3. $\endgroup$ Mar 9, 2018 at 12:15

1 Answer 1


I believe your solution sol is ok. Taking the n-th coefficient of the MMA solution

cn = (4 (-1 + Cos[n \[Pi]]) )/((-4 n + n^3) \[Pi])

Map[Limit[cn,n -> #] &, {0, 2, 4, 6, 8}]
(* {0, 0, 0, 0, 0} *)

Map[Limit[cn,n -> #] &, {1, 3, 5, 7}]
(* {8/(3 \[Pi]), -(8/(15 \[Pi])), -(8/(105 \[Pi])), -(8/(315 \[Pi]))} *) 

even&odd limits conform well with your handsolution. Obviously the Simplify[] for odd and even n is the problem.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.