# Solving delayed PDE

I tried to solve the following delayed PDE, but it's not working at all.

Almost Periodic Case: $$$$\begin{array}{lc} \displaystyle\frac{\partial}{\partial t}w(t,x)= \frac{\partial^2}{\partial x^2 }w(t,x) +\bigg(\dfrac{\cos(2\pi t)}{e^{x+1}+e^1}\bigg) w(t-1,x) + \big(\sin(\pi t)+\sin(t)\big) x(\pi-x)e^x \ \ \\ \\ \hspace{5cm} \text{for} \ \ t\in (0,5) \ \ \text{and} \ \ x\in [0,\pi], \\ \\ w(t,0)=w(t,\pi)=0 \ \ \text{for} \ \ t\in (0,5), \\ \\ w(\theta,x)=(\theta^2-0.2)\big(1-\cos(2x)\big)\ \ \ \text{for} \ \ \ \theta \in [-1,0]\ \ \text{and} \ \ x\in [0,\pi], \end{array} \label{Ex 1}$$$$

This is my code:

ClearAll["Global*"]
(* Define the PDE *)
eqn = D[w[t, x], t] == D[w[t, x], x, x] + (Cos[2 π t]/(Exp[x + 1] + Exp[1])) *
w[t - 1, x] + (Sin[π t] + Sin[t]) x (π - x) Exp[x];
(* Specify initial and boundary conditions *)
ic = w[θ, x] == (θ^2 - 0.2) (1 - Cos[2 x]);
bc = {w[t, 0] == 0, w[t, π] == 0};
(* Solve the PDE numerically *)
sol = NDSolve[{eqn, ic, bc}, w, {t, 0, 5}, {x, 0, π}];
(* Plot the solution at t=5 *)
Plot3D[w[5, x] /. sol, {x, 0, π}, PlotRange -> All, AxesLabel -> {"x", "w"},
MeshFunctions -> {#2 &}, MeshStyle -> {{Thick, Red}}, BoxRatios -> {1, 1, 0.6}]


How can I fix my code?

• Documentation for NDSolve does not mentioned delay PDEs, so it may not be possible. If it were, then we would expect the initial condition to be ic = (w[t /; t < 0, x]) == (t^2 - 0.2) (1 - Cos[2 x]), but that leads to error messages too. I suggest decomposing the PDE into a set of DDEs, as described in tutorial/NDSolveMethodOfLines,. Commented Dec 14, 2023 at 5:19
• If you wish to plot w[5, x], use Plot with the AspectRatio option instead of Plot3D with the BoxRatio option. Commented Dec 14, 2023 at 5:28
• @bbgodfrey Thank you for your replay. Actually I didn't understand your answer. decomposition PDE into a set of DDES, what that means?? Commented Dec 14, 2023 at 10:32
• See mathematica.stackexchange.com/a/78564/1063 for approximating a PDE as a set of coupled ODEs. Commented Dec 14, 2023 at 12:48

Here is a straightforward solution. Because NDSolve apparently cannot solve a delayed PDE, begin by solving the pde for the range {t, 0, 1}, for which the delay can be represented by an auxiliary function, f[t_, x_]:

eqn := D[w[t, x], t] == D[w[t, x], x, x] + (Cos[2 π t]/(Exp[x + 1] + Exp[1]))*
f[t - 1, x] + (Sin[π t] + Sin[t]) x (π - x) Exp[x];
bc = {w[t, 0] == 0, w[t, π] == 0};


(Note that eqn is defined using SetDelayed to accommodate changing the definition of f.)

ic = w[0, x] == -0.2 (1 - Cos[2 x]);
f[t_, x_] := (t^2 - 0.2) (1 - Cos[2 x])
sol[0] = NDSolveValue[{eqn, ic, bc}, w[t, x], {t, 0, 1}, {x, 0, π}];


Next, use sol[0] for the delayed values of w in the range of {t, 1, 2}, and so on.

Do[ic = w[i, x] == sol[i - 1] /. t -> i;
f[tt_, xt_] := sol[i - 1] /. {t -> tt, x -> xt};
sol[i] = NDSolveValue[{eqn, ic, bc},w[t, x], {t, i, i + 1}, {x, 0, π}],
{i, 1, 4}]


Finally, combine the five values of sol to obtain the complete solution.

Piecewise[Table[{sol[i], i <= t <= i + 1}, {i, 0, 4}]];
s = FunctionInterpolation[%, {t, 0, 5}, {x, 0, π}]


For completeness, here is a plot of the solution.

Plot3D[s[t, x], {t, 0, 5}, {x, 0, π}, PlotRange -> All, AxesLabel -> {t, x, w}]
`

There are, of course, alternative methods for solving this problem, one of which is based on my answer to 78493.