# Heat and wave equation [closed]

I have to solve the heat equation

$$\qquad u_t=u_{xx}+0.5 u, 00$$

and

$$\qquad u_x (0,t)=u_x (1,t)=0, u(x,0)=[\cos(\pi x)]^2.$$

I used

uF =
NDSolveValue[
{D[u[x, t], t] == D[u[x, t], {x, 2}] - 0.5*D[u[x, t], x],
u[x, 0] == (Cos[Pi*x])^2, D[u[0, t]] == 0, D[u[1, t]] == 0},
u, {x, 0, 1}, {t, 0, 2}]
Plot3D[uF[x, t], {x, 0, 1}, {t, 0, 2},
AxesLabel -> {"x","t","u"}, PlotRange -> All]


But I get

boundary and initial conditions are inconsistent

Is there a solution by Fourier transformation and using partial sums (e.g., for N = 5, 10, 15)? I need the same thing for

$$\qquad u_{tt}=c^2 u_{xx}, 00$$

and

$$\qquad c=\frac{1}{4 \pi},u(0,t)=u(1,t)=0, u(x,0)=\sin x-\sin{(4x)}+\sin{(9x)}$$

• Which version should be solved, which in the text or which you coded? With version 12.1 both equations can be solved symbolically. – rmw Mar 25 at 18:57
• Both of them if possible, thank you – George Mar 25 at 18:58

 uF = NDSolveValue[{D[u[x, t], t] == D[u[x, t], {x, 2}] - 1/2*D[u[x, t], x],
u[x, 0] == (Cos[Pi*x])^2, Derivative[1, 0][u][0, t] == 0, Derivative[1, 0][u][1, t] == 0}, u, {x, 0, 1}, {t,0,1},
Method -> {"MethodOfLines","SpatialDiscretization" -> {"TensorProductGrid","MinPoints" -> 40}}];

Plot3D[uF[x, t], {x, 0., 1.}, {t, 0., 0.2}, PlotRange -> All] uF2 = DSolveValue[{D[u[x, t], t] == D[u[x, t], {x, 2}] - 1/2*u[x, t],
u[x, 0] == (Cos[Pi*x])^2, Derivative[1, 0][u][0, t] == 0, Derivative[1, 0][u][1, t] == 0}, u, {x, t}] it's a warning because there's a singularity at the boundary at t=0.

Your BC has $$u(0,0)=u(1,0) = 0$$ but your IC has $$u(0,0) = u(1,0) = 1$$.