2
$\begingroup$

I have to solve the heat equation

$\qquad u_t=u_{xx}+0.5 u, 0<x<1,t>0$

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}, 0<x<\pi,t>0$

and

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

$\endgroup$
  • 1
    $\begingroup$ Which version should be solved, which in the text or which you coded? With version 12.1 both equations can be solved symbolically. $\endgroup$ – rmw Mar 25 at 18:57
  • $\begingroup$ Both of them if possible, thank you $\endgroup$ – George Mar 25 at 18:58
5
$\begingroup$
 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]

enter image description here

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}]

enter image description here

|improve this answer|||||
$\endgroup$
1
$\begingroup$

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$.

|improve this answer|||||
$\endgroup$

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