# NDSolve is not always easy to handle [duplicate]

I solve the PDE system analytically and numerically and get totally different results. Should there be a solution to the problem of the numerical solution, one must ask oneself - do you know the correct result beforehand? Unfortunately, Mathematica is still very weak in solving analytical PDEs.

pde = D[u[x, t], t] == D[u[x, t], x, x];
bcs = {Derivative[1, 0][u][0, t] == 0, Derivative[1, 0][u][1, t] == 0};
ic = u[x, 0] == x;
sol = First@DSolve[{pde, bcs, ic}, u, {x, t}] /. K -> n U[x_, t_] = u[x, t] /. sol /. \[Infinity] -> 20 // Activate;
Plot3D[U[x, t], {x, 0, 1}, {t, 0, 0.5}, PlotRange -> All, BoxRatios -> {1, 1, 0.8}, PlotTheme -> "Default"] Check the boundary conditions for compliance.

Derivative[1, 0][U][0, t]
0
Derivative[1, 0][U][1, t]
0


Now the numerical solution attempt:

nsol = First@NDSolve[{pde, bcs, ic}, u, {x, 0, 1}, {t, 0, 0.5}] Plot3D[u[x, t] /. nsol, {x, 0, 1}, {t, 0, 0.5}, PlotRange -> All, BoxRatios -> {1, 1, 0.8}, PlotTheme -> "Default"] To the left of the error warning (...), there are sources that can help with problem solving. Unfortunately I did not find any.

• Is this just a statement..or is there a specific question...sorry, im not sure what you’re looking for. – morbo Jun 7 '19 at 16:27
• I want to solve it numericaly. – rmw Jun 7 '19 at 16:28
• To be more specific, add Method -> {"MethodOfLines", "DifferentiateBoundaryConditions" -> {True, "ScaleFactor" -> 100}} will resolve your problem. – xzczd Jun 7 '19 at 16:38
• @xzczd I found the source in "The Numerical Method of Lines," but not without your help, thank you. I think Maple is more helpful in solving PDEs in many cases. – rmw Jun 7 '19 at 17:25
• Indeed, Maple is more good at symbolic PDE solving: 12000.org/my_notes/pde_in_CAS/maple_2019_and_mma_12/index.htm , at least now. But its numeric PDE solver isn't that good, AFAIK. – xzczd Jun 7 '19 at 18:00