My Mathematica skills aren't the best but this solution isn't making sense considering the boundary value I am supplying.
The leftmost boundary condition, i.e. at $x=0$, $c[t,x]$ should be $1$ for $t\leq 1$ and $0$ for $t>1$. i.e. $$c[t\leq1,0]=1$$ $$c[t>1,0]=0$$ However the solution from NDSolve when evaluated at any $t>1$, say, $c[2,0]$ is non-zero. Why? Is it the way I am solving the PDEs or? I have tried other methods other than the piecewise but also no luck.
Clear[Derivative]
tfinal = 50;
L = 10;
difeqns1 = {D[c[t, x], {t, 1}] + D[c[t, x], {x, 1}] +
D[q[t, x], {t, 1}] == 0,
D[q[t, x], {t, 1}] == c[t, x] - q[t, x],
c[0, x] == If[x != 0, 0, 1],
c[t, 0] == Piecewise[{{1, t <= 1}, {0, t > 1}}, 0],
q[0, x] == If[x != 0, 0, 0]};
solv = NDSolve[
difeqns1, {c[t, x], q[t, x]}, {t, 0, tfinal}, {x, 0, L},
Method -> {"MethodOfLines",
"SpatialDiscretization" -> "TensorProductGrid"}];
c[t, x] /. solv /. t -> 2 /. x -> 0


If[x != 0, 0, 1] & If[x != 0, 0, 0]code constructions? Which output do you expect? – Ulrich Neumann Jan 18 '24 at 17:04If[x != 0, 0, 0]Should return 0 everywhere initially for $q$. I constructed it that way because I wanted to have nonzero options as well, but yes for this example I could have simply have saidq[0,x]==0. As forIf[x != 0, 0, 1]that should return $c[0,0]=1$ and $c[0,x>0]=0$ unless I have misinterpreted how that works. As far as I could tell, $c[0,0]$ should return a value of $1$ in both those conditions? – Kendall Jan 18 '24 at 18:56Method -> {"MethodOfLines", "DifferentiateBoundaryConditions" -> {True, "ScaleFactor" -> 100}}should resolve the problem. To learn more aboutDifferentiateBoundaryConditions, see also https://mathematica.stackexchange.com/a/127411/1871 – xzczd Jan 19 '24 at 08:57