# Solve and plot PDE on restricted domain

I want Mathematica to solve (I used a picture since when I use mathjax code the editor here says I might be using wrongly formatted code...)

So far, I have

pde = D[f[x,t], t] - D[f[x,t], {x,2}] == 0
sol = DSolve[{pde, f[x,0] == Min[x , 1 - x], f[0,t] == 0, f[1,t] == 0}, f[x,t], {x,0,1},{t,0,Infinity}]


But I am not sure if it is taken in account that $$x \in (0,1)$$ and $$t > 0$$. Do I have to somehow use the Piecewise function as they do here?

My second question concerns plotting the solution. The output of the above code snippet is This is a function of two variables with values in $$\mathbb{R}$$, so it should easily be plottable. But when I use

Plot3D[f[x, t] /. sol, {x, 0, 1}, {t, 0, 4}]


as suggested here, I just get an empty 3d box.

• Also, when using DSolve, Why do you write f[x,t], {x,0,1},{t,0,Infinity}], instead of f[x,t], {x,t}] ? – Nasser Jul 29 '19 at 13:16
• @Nasser Because I want the solution only to be for $x \in (0,1)$ and $t > 0$. – Viktor Glombik Jul 29 '19 at 13:17
• You can add assumptions DSolve[..., Assumptions -> {t > 0, 0 < x < 1}] but it will not make any difference to the solution. It is analytical solution. You decide when running the solution, what range and time you can to look at. This is different from NDSolve. – Nasser Jul 29 '19 at 13:54

You can try

ClearAll[f, x, t];
pde = D[f[x, t], t] - D[f[x, t], {x, 2}] == 0
bc  = {f[0, t] == 0, f[1, t] == 0};
ic  = {f[x, 0] == Min[x, 1 - x]};
sol = f[x, t] /. First@DSolve[{pde, ic, bc}, f[x, t], {x, t}];
sol = Activate[sol /. Infinity -> 20];

Manipulate[
Quiet@Plot[sol /. t -> time, {x, 0, 1},PlotRange -> {Automatic, {0, .5}}],
{{time, 0, "time"}, 0, .51, .01}
] Update Here is 3D plot requested

Plot3D[sol, {t, 0, .5}, {x, 0, 1}, PlotRange -> All,
AxesLabel -> {"time", "space", "f(x,t)"}, BaseStyle -> 14]


PLotted for $$0 and up to $$t=0.5$$ seconds. • @ViktorGlombik if you mean 3D? Yes. But you can see that it decays to zero after 0.5 seconds. Will add 3D soon. I use LICEcap program to export animation from Mathematica to gif file. – Nasser Jul 29 '19 at 14:04
• What does First@DSolve do? – Viktor Glombik Jul 30 '19 at 23:01