Consider these code, which solve the same equation using DSolve and NDSolve, why do they give different answer? I'm using version 11.0 on Windows 8.1.
eq = D[u[x, t], t] == D[u[x, t], x, x];
icsbc = {u[x, 0] == 1, u[0, t] == 0, u[1, t] == 0};
numer1 = NDSolve[{eq, icsbc}, u, {x, 0, 1}, {t, 0, 1}]
numer2 = NDSolve[{eq, icsbc}, u, {x, 0, 1}, {t, 0, 1},
Method -> {"MethodOfLines",
"SpatialDiscretization" -> "FiniteElement"}]
numer3 = NDSolve[{eq, icsbc}, u, {x, 0, 1}, {t, 0, 1},
Method -> {"MethodOfLines",
"SpatialDiscretization" -> {"TensorProductGrid",
"MinPoints" -> 200}}]
symbol = DSolve[{eq, icsbc}, u[x, t], {x, t}]
symbol = {{u[x, t] ->
Inactive[Sum][-((
2 (-1 + (-1)^K[1]) E^(-\[Pi]^2 t K[1]^2)
Sin[\[Pi] x K[1]])/(\[Pi] K[1])), {K[1], 1, \[Infinity]}]}}
Plot[{Evaluate[u[x, 1/2] /. numer1], Evaluate[u[x, 1/2] /. numer2],
Evaluate[u[x, 1/2] /. numer3],
Evaluate[(u[x, t] /. symbol[[1]] /. t -> 1/2 /. {Infinity -> 10} //
Activate)]}, {x, 0, 1},
PlotLegends -> {"numeric1", "numeric2", "numeric3", "symbolic"},
PlotStyle -> {{Green, Dashing[{0.1, 0.1}], Thin}, {Blue,
Dashing[{0.05, 0.05}], Thin}, {Yellow, Dashing[{0.01, 0.01}],
Thin}, {Black, Thickness[0.02]}}]
Another example:
L = 2;
eq = D[u[x, t], t] == D[u[x, t], x, x];
opts = Method -> {"MethodOfLines",
"SpatialDiscretization" -> {"FiniteElement",
"MeshOptions" -> {"MaxCellMeasure" -> 0.001}}};
sol1 = NDSolveValue[{eq, u[x, 0] == x, u[0, t] == 1, u[2, t] == 1},
u, {x, 0, L}, {t, 0, L}, opts];
sol2 = u[x, t] /.
First@DSolve[{eq, u[x, 0] == x, u[0, t] == 1, u[2, t] == 1},
u[x, t], {x, t}]
(* 1 + Inactive[Sum][-((
2 (1 + (-1)^K[1]) E^(-(1/4) \[Pi]^2 t K[1]^2)
Sin[1/2 \[Pi] x K[1]])/(\[Pi] K[1])), {K[1], 1, \[Infinity]}] *)
T = 1/10;
Plot[{Evaluate[sol1[x, T]],
Evaluate[sol2 /. {Infinity -> 100} /. t -> T // Activate]}, {x, 0,
L}, PlotLegends -> {"numeric solution", "symbolic solution"}]
NDSolve::ibcinc: Warning: boundary and initial conditions are inconsistent.
error? YourDSolve
code returns unevaluated for me. $\endgroup$ – march Dec 12 '16 at 18:41icsbc = {u[x, 0] == UnitStep[x - 0.001] UnitStep[0.999 - x], u[0, t] == 0, u[1, t] == 0};
instead, evaluate the numerical solutions, and plot a time-sequence of plots of the temperature profile. You'll see it decay to zero very quickly. $\endgroup$ – march Dec 12 '16 at 18:46numer2
solution I'm don't get any error messages $\endgroup$ – Mariusz Iwaniuk Dec 12 '16 at 18:47{"MethodOfLines", "DifferentiateBoundaryConditions" -> {True, "ScaleFactor" -> 100}}
as the method ofNDSolve
will resolve the problem. $\endgroup$ – xzczd Dec 13 '16 at 3:16