Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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!

share|improve this question
1  
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
add comment

1 Answer 1

Based on the comments above

\[Phi][x_] := Piecewise[{{1, Abs[x] < 1}, {0, Abs[x] >= 1}}];
pde = D[u[x, t], t] - 1/4 D[u[x, t], {x, 2}] == 0 ; soln = 
NDSolve[{pde, u[x, 0] == \[Phi][x]}, u[x, t], {x, -5, 5}, {t, 0, 10}]
ffn[x_, t_] = u[x, t] /. soln // First
Animate[Plot[ffn[x, t], {x, -5, 5}, PlotRange -> {{-5, 5}, {0, 1}}, 
Filling -> Axis, ColorFunction -> "TemperatureMap", 
ColorFunctionScaling -> False], {t, 0, 10}, 
AnimationRunning -> False]

heat

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.