# Specifying initial conditions for a PDE

I have simple diffusion equation with point source at c(0, t) = 1 and initial condition c(elsewhere, 0) = 0. How should I apply DSolve or NDSolve to solve the equation ? I have tried specifying my initial conditions like this:

ic = {c[x > 0, 0] == 0, c[x < 0, 0] == 0, c[0, t] == 1, Derivative[1, 0][c][1, t] == 0}


but it fails. Any suggestions?

Diff = D[c[x, t], t] - D[c[x, t], {x, 2}] == 0;
ic = {c[x > 0, 0] == 0, c[x < 0, 0] == 0, c[0, t] == 1, Derivative[1, 0][c][1,t] == 0};
s1 = NDSolve[{Diff, ic}, {c[x, t]}, {x, 0, 1}, {t, 0, 1}];
Plot3D[c[x, t] /. s1, {x, 0, 1}, {t, 0, 1}]

• Have a look at DSolve and NDSOlve. There are many examples in the documentation. Aug 27, 2014 at 9:03
• Can you show the rest of your input? Aug 27, 2014 at 12:10
• Ofcourse, Diff = D[c[x, t], t] - D[c[x, t], {x, 2}] == 0; ic = {c[x > 0, 0] == 0, c[x < 0, 0] == 0, c[0, t] == 1, Derivative[1, 0][c][1, t] == 0}; s1 = NDSolve[{Diff, ic}, {c[x, t]}, {x, 0, 1}, {t, 0, 1}]; Plot3D[c[x, t] /. s1, {x, 0, 1}, {t, 0, 1}]; any advice/suggestions will be greatly appreciated! Aug 27, 2014 at 13:14

## 1 Answer

Your syntax c[x > 0, 0] is not valid, try this:

 Diff = D[c[x, t], t] - D[c[x, t], {x, 2}] == 0;
ic = {c[x, 0] == If[x != 0, 0, 1], c[0, t] == 1,
Derivative[1, 0][c][1, t] == 0};
s1 = NDSolve[{Diff, ic}, {c[x, t]}, {x, 0, 1}, {t, 0, 1}];


You get a solution, however note that B.C. is ill conditioned in that the soluion must go sharply from zero to 1 right at the corner.

 Plot3D[c[x, t] /. s1, {x, 0, 1}, {t, 0, 1}]


If you look at the solution along t=0 you see it struggling to satisfy the incompatible conditions: