I have a PDE problem, and here is my code:
solN = Module[{k = 1, A = 1, u0 = 1, l = 1, \[Beta] = 1, T = 10},
NDSolveValue[{D[u[x, t], t] - k D[u[x, t], x, x] ==
A Exp[-\[Beta] t] + NeumannValue[0, x == 0], u[l, t] == 0,
u[x, 0] == u0}, u, {x, 0, l}, {t, 0, T},
Method -> {"PDEDiscretization" -> {"MethodOfLines",
"SpatialDiscretization" -> {"FiniteElement"}}}]]
Manipulate[Plot[{solN[x, t]}, {x, 0, 1}, PlotRange -> {0, 1.3}], {t, 0, 1}]
From the manipulation we can see that the solution contradicts the boundary condition at x==1
, so how to fix that?
Edit:
I know the initial conditions contradict the boundary conditions at point x==1,t==0
, however this PDE has an analytical solution. The following codes
show the analytical solution and its plot.
nsol = Compile[{x, t, n}, Module[{k = 1, A = 1, u0 = 1, l = 1, \[Beta] = 1},
Sum[(Sqrt[2]*Cos[(Pi*x*(-1 + 2*i))/(2*l)]*((2*(-1)^i*Sqrt[2]*Sqrt[l]*u0)/(E^((k*Pi^2*t*(-1 + 2*i)^2)/(4*l^2))*(Pi - 2*Pi*i)) +
(8*(-1)^i*Sqrt[2]*A*(E^((-t)*\[Beta]) - E^(-((k*Pi^2*t*(1 - 2*i)^2)/(4*l^2))))*l^(5/2))/((-4*l^2*\[Beta] + k*Pi^2*(1 - 2*i)^2)*(Pi - 2*Pi*i))))/Sqrt[l], {i, 1, n}]]]
Manipulate[
Plot[nsol[x, t, n], {x, 0, 1},
PlotRange -> {0, 1.3}], {t, 0, 1}, {n, Range[100]}]