3
$\begingroup$

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"}]

enter image description here

$\endgroup$
2
  • 1
    $\begingroup$ Related: mathematica.stackexchange.com/a/127411/1871 So an old-fashined way to fix the problem is to set 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. ) $\endgroup$
    – xzczd
    Jun 19 '17 at 10:54
  • $\begingroup$ @xzczd.Thanks.1 for good comment. $\endgroup$ Jun 19 '17 at 20:19
2
$\begingroup$

The analytical solution is correct. You can correct the numerical solution by fixing your initial conditions. One way is as follows

eq = {D[u[x, t], {x, 2}]*k == D[u[x, t], t], u[0, t] == 0, 
   u[1, t] == 0, u[x, 0] == If[x == 1, 0, x]};

Mathematica graphics

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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