Why numericall solution is different than symbolic?
k = 5;
eq = {D[u[x, t], {x, 2}]*k == D[u[x, t], t], u[0, t] == 0,
u[1, t] == 0, u[x, 0] == x};
sol = NDSolve[eq, u, {x, 0, 1}, {t, 0, 10},
Method -> {"MethodOfLines",
"SpatialDiscretization" -> "FiniteElement"}];
sol2 = u[x, t] /. First@DSolve[eq, u[x, t], {x, t}];
Plot[{u[x, t] /. sol /. x -> 1/2,
sol2 /. x -> 1/2 /. {Infinity -> 100} // Activate}, {t, 0, 10},
PlotRange -> All, PlotLegends -> {"Numeric", "Symbolic"}]


Method -> {"MethodOfLines", "DifferentiateBoundaryConditions" -> {True, "ScaleFactor" -> 100}}, but I'm not sure about how to fix it when"FiniteElement"is chosen. (I should say the result is somewhat surprising, according to this answer"FiniteElement"seems to be free from this problem. ) – xzczd Jun 19 '17 at 10:541for good comment. – Mariusz Iwaniuk Jun 19 '17 at 20:19