# Trying to solve a differential equation with a piecewise initial condition

I am trying to solve $$u_t=\frac{1}{4}u_{xx}$$ $-\infty<x<\infty,\: t>0$

With the initial condition $u(x,0)=\phi(x)$ where

$$\phi(x)= \left\{ \begin{array}{lr} 1 & |x|<1\\ 0 & |x|\geq 1 \end{array} \right.$$

So I initially typed in my piecewise function like this

ϕ[x_] := Piecewise[{{1, Abs[x]<1}, {0, Abs[x] >= 1}}]


But I have also tried this, (are they both valid, or is just one, or is neither?)

ϕ[x_] := Piecewise[{{1, -1 < x < 1}, {0, x >= 1 || x <= -1}}]


Then, following the mathematica examples I tried to solve the differential equation:

pde = D[u[x, t], t] - 1/4 D[u[x, t], {x, 2}] == 0
soln = DSolve[{pde, u[x, 0] == ϕ[x]}, u[x, t], {x, t}]


Which outputs a bunch of weird stuff, not the solution (I think) I was expecting. If my math is correct I think the solution to this would involve the error function. Any tips to where I might be going wrong would be aprreciated!

-
DSolve can't handle heat conduction equation, consider NDSolve instead if a numerical solution is OK, or you can refer to this post. –  xzczd Mar 26 at 2:49
You may not like this answer: use NDSolve, it works in this case. –  János Tóth Mar 26 at 9:00
Observe that you may also use $\phi$[x_] = UnitBox[x/2]. –  murray Mar 27 at 16:05

\[Phi][x_] := Piecewise[{{1, Abs[x] < 1}, {0, Abs[x] >= 1}}];