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[1] -> 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.




Method -> {"MethodOfLines", "DifferentiateBoundaryConditions" -> {True, "ScaleFactor" -> 100}}will resolve your problem. – xzczd Jun 07 '19 at 16:38