# Analyitic and numerical solutions plots of PDE are different! [closed]

I solved the following heat equation PDE analytically by hand and also Maple the solutions were the same.

Also, I solved the PDE numerically using Maple. But the analytic solution and numerical solution plots are different with each other! Why?! And which one is correct?

For validating Maple's numerical solution, I solved the PDE using Mathematica (NDSolve) ,too and it gave me the same plot as Maple's numerical plot. $$$$u_{t}-u_{xx}=0$$$$

$$$$0

$$$$t>0$$$$

Boundary Conditions:

$$\begin{cases}u(0,t)+u_{x}(0,t)=1\\u(\pi,t)+u_{x}(\pi,t)=-1\end{cases}$$

Initial Condition:

$$$$u(x,0)=sin(x)$$$$

Maple analytic solution and code:

PDE3 := {u(0, t)+(D[1](u))(0, t) = 1, u(Pi, t)+(D[1](u))(Pi, t) = -1, diff(u(x, t), x$2) = diff(u(x, t), t), u(x, 0) = sin(x)}; sol3 := assuming([pdsolve(PDE3)], [0 < x and x < Pi, t > 0]); plot3d(subs(infinity = 1000, rhs(sol3)), x = 0 .. Pi, t = 0 .. 0.5e-1);  Maple numerical code: PDE4 := {diff(u(x, t), x$2) = diff(u(x, t), t)}
IBC := {u(0, t)+(D[1](u))(0, t) = 1, u(Pi, t)+(D[1](u))(Pi, t) = -1, u(x, 0) = sin(x)}
sol4 := pdsolve(PDE4, IBC, numeric)
plot3d(subs(infinity = 1000, rhs(sol3)), x = 0 .. Pi, t = 0 .. 0.5e-1)


Maple Analytic Solution Plot:

Maple Numerical Solution Plot:

Mathematica Numerical Solution Plot:

• Add Wolfram code for your Mathematica plot. At first glance it seems you just need to add the BoxRatios -> 1 option to your Mathematica plot. Jan 24, 2019 at 1:00
• @Edmund There is no problem with Mathematica's plot that's just for validating the Maple's numerical solution. The Mathematica's plot validates the numerical solution plot of Maple. The problem is: Why numerical and analytical plots are different? Jan 24, 2019 at 1:13
• Since 2 out of 3 approaches agree, I'd guess the Maple analytical solution is wrong :) Actual evidence: it doesn't look like the Maple analytical solution matches the initial conditions. Jan 24, 2019 at 2:01
• I'm voting to close this question as off-topic because it's more of a Maple question than a Mathematica question. Jan 24, 2019 at 3:35
• Side note: With the help of LaplaceTransform and easyFourierTrigSeries, it's possible to show a correct series solution is $$e^{-t} \sin (x)-\frac{e^{-t}}{\pi }-\frac{e^t}{\pi }+\frac{4}{\pi } \left(\frac{\pi }{4}-\frac{x}{2}\right)+\frac{2}{\pi }-\frac{4}{\pi } \sum _{k}^{\infty } \left(\frac{e^{-4 k^2 t} (2 k \cos (2 k x)-\sin (2 k x))}{2 k \left(-1+4 k^2\right) \left(1+4 k^2\right)}+\frac{e^{-t} (-\cos (2 k x)+2 k \sin (2 k x))}{2 \left(-1+4 k^2\right)}+\frac{e^t (\cos (2 k x)+2 k \sin (2 k x))}{2 \left(1+4 k^2\right)}\right)$$ Jan 24, 2019 at 7:45

Maple analytical solution appears to be wrong. It does not even satisfy the initial conditions. Mathematica currently can not solve this PDE analytically (but this is better than solving it and giving wrong solution ;)

Here is side by side animation of Maple solution and Mathematica animated for one second.

## Maple

restart;
PDE3 := diff(u(x, t), x\$2) = diff(u(x, t), t):
ic:= u(x, 0) = sin(x):
bc:= u(0, t)+(D[1](u))(0, t) = 1, u(Pi, t)+(D[1](u))(Pi, t) = -1:
sol3 := pdsolve([PDE3,ic,bc],u(x,t)):
sol:=subs(infinity=20,rhs(sol3)):
plots:-animate(plot,[sol,x=0..Pi],t=0..1,frames=100)


## Mathematica

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

Manipulate[
Grid[{{Row[{"t=",t}]},
{Plot[Evaluate[u[x,t]/.sol],{x,0,Pi},
PlotRange->{{0,Pi},{-1,1}},ImageSize->300,
Ticks->{{0,Pi/4,Pi/2,3/4 Pi,Pi},Automatic}]
}}],
{{t,0,"time"},0,1,.01,Appearance->"Labeled"}
]


## Animation

Maple

Mathematica

May be you can report this bug to Maplesoft.

• Thank You! I posted a new question which shows my analytic solution of the problem which is not compatible with Mathematica's numerical solution again. Would you please look at that? mathematica.stackexchange.com/questions/190169/… Jan 24, 2019 at 12:10