# Solving a heat equation on a finite interval with Neuman boundary conditions

I am new to Mathematica and need to verify my numerical result. Can anyone please show me how to solve the following heat equation problem $$u_t = u_{xx}$$ on the interval $$x \in [0,1]$$. The initial condition is $$u(x,0) = (\sin(\pi x))^{100}$$ and Neumann boundary conditions $$u_x(0,t)=u_x(1,t)=0$$

I was hoping to plot the solution at time $$t=1$$ with respect to $$x$$. Can anyone please help me? I am a complete novice and the internet was not much help.

Edit: this is what I have managed to use for the equation

sol2 = NDSolveValue[{D[u[t, x], {t, 1}] - D[u[t, x], {x, 2}] ==
NeumannValue[0, x == 0] + NeumannValue[0, x == 1],
u[0, x] == (Sin[Pi*x])^100}, u, {x, 0, 1}, {t, 0, 2},
Method -> {"MethodOfLines",
"SpatialDiscretization" -> {"FiniteElement"}}];


but I have no idea how to plot

• Could you include what you did with NDSolve[]? Feb 11 at 5:59
• @J.M. thank you, to be honest, I do not know how to use that function Feb 11 at 6:01
• @J.M. I am very new to Mathematica and only know the basic syntax. I come from Matlab Feb 11 at 6:05
• There is an entire Heat Transfer tutorial. That should have everything you need for setting up a numerical solution. Feb 11 at 7:14
• Can you show me what you tried than I can explain it. Feb 11 at 7:36

"startup aid"

U = NDSolveValue[{Derivative[0, 1][u][x, t] ==Derivative[2, 0][u][x, t],
u[x, 0] == Sin[Pi x]^100 },
u, {t, 0, 1}, {x, 0, 1} ,
Method -> {"MethodOfLines", "TemporalVariable" -> t,"SpatialDiscretization" -> "FiniteElement"  }]


NDSolveValue evaluates the solution U[x,t] as an interpolation object. "FiniteElement" sets the Neumann boundary conditions to zero.

Plot3D[U[x, t], {x, 0, 1 }, {t, 0, .1},PlotRange -> {0, 1}, MeshFunctions -> {#2 &}, MaxRecursion -> 5] • thank you very much for this. I think I understand how to use the solve command now. But how do I plot the solution at T=1 (for a specific value of T) with respect to X as a curve rather than a surface? Feb 11 at 7:45
• Plot[U[x,1],{x,0,1}] Feb 11 at 7:55
• @user21 "Method" is needed because I omit Neumann-bc I think. Without "Method" Mathematica 12 gives a warning but evaluates correct solution . Feb 11 at 8:34
• @UlrichNeumann, yes, you are correct about that. Feb 11 at 8:37

Also you can it try this way with version 12.2

sol = NDSolveValue[{D[u[t, x], t] + DiffusionPDETerm[{u[t, x], {x}}] == 0,
u[0, x] == (Sin[Pi*x])^100}, u, {x, 0, 1}, {t, 0, 2}]

Plot3D[sol[t, x], {x, 0, 1}, {t, 0, 0.1}, PlotRange -> All] To complete this, the following addition:

heatSol =
NDSolveValue[{HeatTransferPDEComponent[{u[t, x], t, {x}}, <|"ThermalConductivity" -> {{1}}|>] == 0,
u[0, x] == (Sin[Pi*x])^100}, u, {x, 0, 1}, {t, 0, 2}]


The heattransfer at t =1:

Plot[heatSol[1, x], {x, 0, 1}] 