# Solve Heat Equation with Source Term and Neumann BC

I am trying to find a solution on mathematica to

$$\partial_tu-\partial_{xx}u= \cos(2\pi x), \; 00$$

$$\partial_xu(0,t)=\partial_xu(1,t)=0, \; t>0$$

$$u(x,0) = \sin^2(3\pi x), \; 0 \leq x \leq 1$$

to be able to check my answers when working them out by hand. I have tried several methods, two of which I will list here:

• Method 1
sol = NDSolve[{D[u[t, x], {t, 1}] - D[u[t, x], {x, 2}] == Cos[2 \[Pi] x], Derivative[0, 1][u][t, 0] == 0 , u[0, x] == Sin[3 \[Pi] x]^2}, u, {x, 0, 1}, {t, 0, 10}];


This gives me an output of an interpolating function. Is there any way to get an explicit answer?

• Method 2
eqn = D[u[x,t],t]-D[D[u[x,t],x],x]==Cos[2 \[Pi] x];
BC1 = D[u[x,t],t]/.x->0==0;
BC2 = D[u[x,t],t]/.x->1==0;
IC = u[x,0]==Sin[3\[Pi]x]^2;
DSolve[{eqn,BC1,BC2,IC},u[x,t],{x,t}]

However, I do not think I am using the right functions to solve this. DSolve, NDSolve? any suggestions would be very welcome. I am trying to read up on their website how to solve PDEs.

Thank you

• There are typos in method 1; try sol = NDSolve[{D[u[t, x], {t, 1}] - D[u[t, x], {x, 2}] == Cos[2 \[Pi] x], Derivative[0, 1][u][t, 0] == 0 , u[0, x] == Sin[3 \[Pi] x]^2}, u, {x, 0, 1}, {t, 0, 10}]. – b.gates.you.know.what May 14 at 15:51
• thanks for the comment, i get NDSolve::ibcinc: Warning: boundary and initial conditions are inconsistent. NDSolve::bcart: Warning: an insufficient number of boundary conditions have been specified for the direction of independent variable x. Artificial boundary effects may be present in the solution. u-> interpolating function scalar hermite – elcharlosmaster May 14 at 15:51

pde = D[u[x, t], t] - D[u[x, t], x, x] == Cos[2 \[Pi] x]; Plot3D[sol, {x, 0, 1}, {t, 0, 5}, PlotRange -> All] 