5
$\begingroup$

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

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

2 Answers 2

2
$\begingroup$

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

enter image description here

$\endgroup$
4
  • $\begingroup$ 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? $\endgroup$
    – user77278
    Feb 11, 2021 at 7:45
  • $\begingroup$ Plot[U[x,1],{x,0,1}] $\endgroup$ Feb 11, 2021 at 7:55
  • $\begingroup$ @user21 "Method" is needed because I omit Neumann-bc I think. Without "Method" Mathematica 12 gives a warning but evaluates correct solution . $\endgroup$ Feb 11, 2021 at 8:34
  • $\begingroup$ @UlrichNeumann, yes, you are correct about that. $\endgroup$
    – user21
    Feb 11, 2021 at 8:37
4
$\begingroup$

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]

enter image description here

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

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.