13
$\begingroup$

Could someone possibly gives an insight as to why DSolve can solve

$$ \frac{\partial^{2}u}{\partial t^{2}}=\frac{\partial^{2}u}{\partial x^{2} }\qquad t>0 $$

But not this very similar PDE

$$ \frac{\partial^{2}u}{\partial t^{2}}+u=\frac{\partial^{2}u}{\partial x^{2} }\qquad t>0 $$

Since the process of solving these by separation of variables is almost identical. In the second PDE, the time ODE to solve is $T^{\prime\prime }+\left( 1+n^{2}\right) T=0$ while in the first PDE the time ODE to solve is $T^{\prime\prime}+n^{2}T=0$. Everything else is the same.

So I am baffled why Mathematica can solve one PDE but not the other. I thought if one can understand better why it could not solve it, that will be useful thing to know when trying other problems by knowing better what are the limitation they should expect in advance.

So this question is asking to find why it could not solve it. I know this might be hard for users since we have no access to the source code. Also if someone can show a workaround, to solve this, using DSolve that will be accepted also.

Here is analytical solution to the second PDE (the one that can't be solved by Mathematica).

Here is analytical solution to the first one.

Solve, $0<x<\pi$

$$ \frac{\partial^{2}u}{\partial t^{2}}+u=\frac{\partial^{2}u}{\partial x^{2} }\qquad t>0 $$

Boundary conditions, $t>0$ (both ends fixed)

\begin{align*} u\left( 0,t\right) & =0\\ u\left( \pi,t\right) & =0 \end{align*}

Initial conditions, $t=0$

\begin{align*} \frac{\partial u\left( x,0\right) }{\partial t} & =0\\ u\left( x,0\right) & =\sin^{2}\left( x\right) \end{align*}

Analytical solution:

Dispersion term $u$ causes the shape of the original wave to distort with time. Using separation of variables, Let $u=X\left( x\right) T\left( t\right) .$ Substituting this back in the PDE gives

\begin{align*} T^{\prime\prime}X+XT & =X^{\prime\prime}T\\ \frac{T^{\prime\prime}}{T}+1 & =\frac{X^{\prime\prime}}{X}=-\lambda \end{align*}

The eigenvalue ODE\ is

\begin{align*} X^{\prime\prime}+\lambda X & =0\\ X\left( 0\right) & =0\\ X\left( \pi\right) & =0 \end{align*}

The eigenvalues are $\lambda_{n}=\left( \frac{n\pi}{L}\right) ^{2} ,n=1,2,3,\cdots$ and $L=\pi$ here, then $\lambda_{n}=n^{2}$ and the eigenfunctions are $X_{n}\left( x\right) =c_{n}\sin\left( nx\right) $. The time ODE\ becomes

\begin{align*} T^{\prime\prime}+\left( 1+\lambda_{n}\right) T & =0\\ T^{\prime\prime}+\left( 1+n^{2}\right) T & =0 \end{align*}

The roots of the characteristic equation are $\pm i\sqrt{1+n^{2}}$, since $n^{2}\geq1$. Hence the solution of the above ODE\ is

$$ T_{n}\left( t\right) =A_{n}\cos\left( t\sqrt{1+n^{2}}\right) +B_{n} \sin\left( t\sqrt{1+n^{2}}\right) $$

Taking time derivatives gives

$$ T_{n}^{\prime}\left( t\right) =-\sqrt{1+n^{2}}A_{n}\sin\left( t\sqrt{1+n^{2}}\right) +B_{n}\sqrt{1+n^{2}}\cos\left( t\sqrt{1+n^{2} }\right) $$

At time $t=0$, the above is zero (initial velocity is zero), which gives

$$ 0=B_{n}\sqrt{1+n^{2}} $$

Hence $B_{n}=0$ and the time ODE solution becomes

$$ T_{n}\left( t\right) =A_{n}\cos\left( t\sqrt{1+n^{2}}\right) $$

Hence the fundamental solution is

\begin{align*} u_{n}\left( x,t\right) & =T_{n}X_{n}\\ & =c_{n}\overset{T_{n}}{\overbrace{\cos\left( t\sqrt{1+n^{2}}\right) } }\overset{X_{n}}{\overbrace{\sin\left( nx\right) }} \end{align*}

Where constant $A_{n}$ merged with $c_{n}$. Therefore the solution is

$$ u\left( x,t\right) =\sum_{n=1}^{\infty}c_{n}\cos\left( t\sqrt{1+n^{2} }\right) \sin\left( nx\right) $$

$c_{n}$ is found from initial position. At $t=0$ the above becomes

$$ \sin^{2}\left( x\right) =\sum_{n=1}^{\infty}c_{n}\sin\left( nx\right) $$

Applying orthogonality gives

$$ \int_{0}^{\pi}\sin^{2}\left( x\right) \sin\left( nx\right) dx=c_{n} \frac{\pi}{2} $$

For $n=2,\int_{0}^{\pi}\sin^{2}\left( x\right) \sin\left( 2x\right) dx=0$, hence $c_{2}=0$ and for $n\neq2$

\begin{align*} \int_{0}^{\pi}\sin^{2}\left( x\right) \sin\left( nx\right) dx & =c_{n}\frac{\pi}{2}\\ c_{n} & =\frac{2}{\pi}\int_{0}^{\pi}\sin^{2}\left( x\right) \sin\left( nx\right) dx\\ & =\frac{2}{\pi}\left( \frac{2\left( \cos\left( \pi n\right) -1\right) }{n^{3}-4n}\right) \\ c_{n} & =\frac{4\left( \left( -1\right) ^{n}-1\right) }{\pi n\left( n^{2}-4\right) }\qquad n\neq2 \end{align*}

Hence solution is

\begin{equation} u\left( x,t\right) =\sum_{n=1,3,4,\cdots}^{\infty}\frac{4\left( \left( -1\right) ^{n}-1\right) }{\pi n\left( n^{2}-4\right) }\cos\left( t\sqrt{1+n^{2}}\right) \sin\left( nx\right) \tag{1} \end{equation}

We see that only difference between the solution to $$ \frac{\partial^{2}u}{\partial t^{2}}+u=\frac{\partial^{2}u}{\partial x^{2} }\qquad t>0 $$

And

$$ \frac{\partial^{2}u}{\partial t^{2}}=\frac{\partial^{2}u}{\partial x^{2} }\qquad t>0 $$

Is just the solution of \ $T^{\prime\prime}+\left( 1+n^{2}\right) T=0$ vs. $T^{\prime\prime}+n^{2}T=0$. Repeating the above separation of variables for $\frac{\partial^{2}u}{\partial t^{2}}=\frac{\partial^{2}u}{\partial x^{2}}$ gives the solution

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

So why did Mathematica solve (2) but not (1)?

Code

ClearAll[u,x,t];
pde=D[u[x,t],{t,2}]==D[u[x,t],{x,2}];
bc={u[0,t]==0,u[Pi,t]==0};
ic={Derivative[0,1][u][x,0]==0,u[x,0]==Sin[x]^2};
sol=DSolve[{pde,bc,ic},u[x,t],{x,t}];
sol=sol/.K[1]->n

Mathematica graphics

Now add dispersion term

ClearAll[u,x,t];
pde=D[u[x,t],{t,2}]+ u[x,t]==D[u[x,t],{x,2}];
bc={u[0,t]==0,u[Pi,t]==0};
ic={Derivative[0,1][u][x,0]==0,u[x,0]==Sin[x]^2};
sol=DSolve[{pde,bc,ic},u[x,t],{x,t}]

Mathematica graphics

Using 11.3 on windows

Update

Added verification by comparing to numerical solution.

enter image description here

Code for the above

pde = D[u[x, t], {t, 2}] + u[x, t] == D[u[x, t], {x, 2}];
ic = {u[x, 0] == Sin[x]^2, Derivative[0, 1][u][x, 0] == 0};
bc = {u[0, t] == 0, u[Pi, t] == 0};
numericalSol = NDSolve[{pde, ic, bc}, u, {x, 0, Pi}, {t, 0, 10}];

cn[n_] := If[n == 2, 0, (4 ((-1)^n - 1))/(Pi n (n^2 - 4))];
mySolution[x_, t_] := Sum[cn[n] Cos[t Sqrt[1 + n^2]] Sin[n x], {n, 1, 20}];

Manipulate[
 opt = {GridLines -> Automatic, GridLinesStyle -> LightGray, 
   PlotRange -> {Automatic, {-1, 1}}, ImageSize -> 300};

 Grid[{
   {Row[{"time ", t}], SpanFromLeft},
   {Plot[Evaluate[u[x, t] /. numericalSol], {x, 0, Pi}, 
     PlotLabel -> "NDSolve", ImageSize -> 300, Evaluate@opt],
    Plot[mySolution[x, t], {x, 0, Pi}, PlotLabel -> "Analytical", 
     PlotStyle -> Red, Evaluate@opt]}
   }, Spacings -> {1, 1}, Alignment -> Center],
 {{t, 0, "time"}, 0, 10, .01, Appearance -> "Labeled"},
 TrackedSymbols :> {t}
 ]

Here is the same plot, but on top of each others. They are an exact match

enter image description here

Code for above is

Manipulate[
 opt = {GridLines -> Automatic, GridLinesStyle -> LightGray, 
   PlotRange -> {Automatic, {-1, 1}}, ImageSize -> 300};

 p1 = Plot[Evaluate[u[x, t] /. numericalSol], {x, 0, Pi}, 
   ImageSize -> 300, Evaluate@opt, PlotStyle -> Blue];
 p2 = Plot[mySolution[x, t], {x, 0, Pi}, PlotStyle -> Red, Evaluate@opt];

 Grid[{
   {Row[{"time ", t}], SpanFromLeft},
   {Show[p1, p2]}
   }, Spacings -> {1, 1}, Alignment -> Center],
 {{t, 0, "time"}, 0, 10, .01, Appearance -> "Labeled"},
 TrackedSymbols :> {t}
 ]
$\endgroup$
7
  • 3
    $\begingroup$ A bit of spelunking shows a DSolve`DSolveWaveEquation function is called, and this function can only solve the 1st pde $\endgroup$
    – xzczd
    Commented Mar 26, 2018 at 12:42
  • 2
    $\begingroup$ Probably limitation. Nothing is perfect. $\endgroup$ Commented Mar 26, 2018 at 15:54
  • 2
    $\begingroup$ I'm surprised that it is solving PDE in analytical form at all. $\endgroup$ Commented Mar 26, 2018 at 17:52
  • 2
    $\begingroup$ What about second terms in formulas (1) and (2) ?, $\;c_2=?$ My solution of the problem $\frac{\partial^{2}u}{\partial t^{2}}+u=\frac{\partial^{2}u}{\partial x^{2} }\quad t>0,\quad 0<x<\pi$ $u\left( 0,t\right)=0,\quad u\left( \pi,t\right)=0,\quad t>0$ $\frac{\partial u\left( x,0\right) }{\partial t} =0,\quad u\left( x,0\right)=\sin^{2}\left( x\right),\quad 0<x<\pi$ is $u=-\frac{8}{\pi}\sum_{n=1}^{\infty }{\left. \frac{\cos{\left( \sqrt{{{\left( 2 n-1\right) }^{2}}+1}\, t\right) } \sin{((2n-1)x)}}{(2n-3)\,(2n-1)\,(2n+1)}\right.}$ $\endgroup$ Commented Jun 9, 2018 at 17:17
  • 1
    $\begingroup$ @xzczd I compared it to numerical NDSolve, I get exact match using only 20 terms in sum. Please see update. $\endgroup$
    – Nasser
    Commented Jun 10, 2018 at 23:45

1 Answer 1

19
$\begingroup$

Unlike integration and even--to a lesser extent--ODEs, in which there are computationally tracktable algorithms for computing answers for broad classes of functions, there aren't really such methods for PDEs. So DSolve must essentially reduce the input a to known template in order to solve it. Apparently we're missing the template for linear dispersion. I will pass this along to the relevant team.

$\endgroup$

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