I'm working on getting a numerical solution for the following PDE: $$ u_t-u_{xx}=0,\ x\in[0,1], t\in[0,1],\\ u(x,0)=\sin(2\pi x),\\ u(0,t)=0,\\ u_x(1,t)=2\pi e^{-t}. $$ The hand solution for this PDE is $u(x,t)=e^{-t}\sin(2\pi x)$.
I tried DSolve
to get the analytical solution.
DSolveValue[{D[u[x, t], {t, 1}] - D[u[x, t], x, x] == 0,
u[x, 0] == Sin[2 \[Pi] x], u[0, t] == 0,
Derivative[1, 0][u][1, t] == 2 \[Pi] E^-t}, u[x, t], {x, t}]
$$\underset{K[1]=1}{\overset{\infty }{\sum }}\sqrt{2} \sin \left(\frac{1}{2} \pi x (2 K[1]-1)\right) \left(-\frac{32 (-1)^{K[1]} \left(-\cosh (t)+e^{-\frac{1}{4} \pi ^2 t (1-2 K[1])^2}+\sinh (t)\right) \sqrt{2}}{\pi \left(4-\pi ^2 (1-2 K[1])^2\right) (1-2 K[1])^2}-\frac{128 (-1)^{K[1]} e^{-\frac{1}{4} \pi ^2 t (2 K[1]-1)^2} \sqrt{2}}{\pi (1-2 K[1])^2 \left(4 K[1]^2-4 K[1]-15\right)}\right)+2 \pi e^{-t} x$$
However, DSolve
gives an answer containing Inactive[Sum]
.
I also tried NDSolve
:
sol = NDSolveValue[{D[u[x, t], {t, 1}] - D[u[x, t], x, x] == 0,
u[x, 0] == Sin[2 \[Pi] x],
u[0, t] == 0, (D[u[x, t], x] /. x -> 1) == 2 \[Pi] E^-t},
u[x, t], {x, 0, 1}, {t, 0, 1},
Method -> {"MethodOfLines",
"SpatialDiscretization" -> {"TensorProductGrid",
"MinPoints" -> 50}}];
Plot3D[{sol, E^-t Sin[2 \[Pi] x]}, {x, 0, 1}, {t, 0, 1}]
It turns out that the numerical solution differs from the analytical one.
I'm confused about this, does my code have any problem or am I missing something here?