How Can Mathematica Be Used to Plot Transient Heating in a Slab?

3 replies · 5K views · last reply
Dustinsfl
Messages
2,217
Reaction score
5
You can find problems with downloadable notebooks now http://www.mathhelpboards.com/f49/engineering-analysis-notes-2882/.

If one boundary is insulated and the other is subjected to and held at a temperature of unity, we wish to determine the solution for the transient heating of the slab.
The governing equation is the usual 1-D heat equation and the boundary conditions (mixed) are given by
\begin{alignat*}{3}
T_x(0,t) & = & 0\\
T(L,t) & = & 1
\end{alignat*}
with initial conditions
$$
T(x,0) = 0.
$$
Obtain the solution to this problem.
For the special case $\alpha = 1$ and $L = \pi$ plot a sequence of the temperature profiles between the initial state and the steady-state, construct a contour plot, density plot, and 3D plot.

Once we solve the problem, we obtain the solution as
$$
T(x,t) = 1 + \frac{4}{\pi}\sum_{n = 1}^{\infty}\frac{(-1)^n}{2n - 1}\cos\left[\left(n - \frac{1}{2}\right)x\right]\exp\left[-\left(n - \frac{1}{2}\right)^2t\right]
$$
Next, we construct all the plots using Mathematica
Code:
Nmax = 40;
L = Pi;
\[Lambda] = Table[(n - 1/2)*Pi/L, {n, 1, Nmax}];
\[Alpha] = 1;
MyTime = Table[t, {t, 0.0001, 1, .05}];
f[x_] = -1;

A = Table[2/L*Integrate[f[x]*Cos[\[Lambda][[n]]*x], {x, 0, L}], {n, 1,Nmax}];

u[x_, t_] = 1+Sum[A[[n]]*Cos[\[Lambda][[n]]*x]*E^{-\[Alpha]*\[Lambda][[n]]^2*t}, {n, 1, Nmax}];

Plot[u[x, MyTime], {x, 0, L}, PlotStyle -> {Red}]

This will produce the graph
https://www.physicsforums.com/attachments/390._xfImport

Adding in this piece of code will produce an animation between the different time profiles.
Code:
Animate[Plot[u[x, t], {x, 0, L}, PlotRange -> {0, 1.1}, GridLines -> Automatic, Frame -> True, PlotStyle -> {Thick, Red}], {t,0, 1, 0.02}, 
 AnimationRunning -> False]
We can produce the contour plot by adding in
Code:
ContourPlot[u[x, y], {x, 0, L}, {y, 0, L}, PlotRange -> All, ColorFunction -> "Rainbow"]

The end result is

https://www.physicsforums.com/attachments/393._xfImport

The density plot
Code:
DensityPlot[u[x, y], {x, 0, L}, {y, 0, L}, PlotRange -> All, ColorFunction -> "Rainbow"]

The plot is
https://www.physicsforums.com/attachments/392._xfImport

And lastly the 3d plot

Code:
Plot3D[u[x, y], {x, 0, L}, {y, 0, L}, PlotRange -> All, Boxed -> False, ColorFunction -> "Rainbow"]

https://www.physicsforums.com/attachments/391._xfImport
Here we can see the Gibbs Phenomenon occurring.
 
Attachments
  • Family of red curves plotted against x from 0 to pi, rising from near 0 at the left to 1 at the right, with oscillations appearing near the right end.
    plotseries1hw3.jpg
    11.9 KB · Views: 166
  • 3D surface plot of temperature T against position x (0 to 3) and time t (0 to 3), with a colour gradient from blue to red and a colour scale from 0 to 1.0.
    3dplot1hw3.jpg
    17.8 KB · Views: 155
  • Density plot of a colour map over x from 0 to 3.1 (horizontal) and t from 0 to 3.1 (vertical), blue at low values rising through green to red at high values, hottest at the upper right.
    density1hw3.jpg
    11.5 KB · Views: 144
  • Filled contour plot over x from 0 to 3.1 (horizontal) and t from 0 to 3.1 (vertical), with bands in blue, teal, green, yellow-orange and red showing the temperature field of transient slab heating.
    contour1hw3.jpg
    13.1 KB · Views: 157
Last edited:
Consider the transient diffusion of heat in a 1-D slab initially with a temperature $f(x)$ that is then subjected to symmetric convective cooling of equal strength at its two boundaries $x = -L$ and $x = L$.
Recognizing that the problem will have a symmetry plane about $x = 0$, the problem may be then treated more simply as one with an insulated condition at $x = 0$ and a convection condition at $x = L$.
With proper non-dimensionalization and assuming for convenience that the ratio of convection and conduction parameters $h/k = 1$, the cooling process is described by the following equations:
\begin{alignat*}{3}
T_t & = & T_{xx}\\
T_x(0,t) & = & 0\\
T_x(1,t) + T(1,t) & = & 0\\
T(x,0) & = & f(x)
\end{alignat*}
For the particular case of $f(x) = 1$, numerically determine the series coefficients $A_n$ and construct a series representation for $T(x,t)$.
Using this series approximation, plot the temperature profiles on the same set of axes for a range of time steps in the dimensionless time interval $t\in [0,4]$ in order to visualize the process.
Robin boundary conditions.
With this problem, let's identify the first 40 eigenvalues and construct the same plots.
In solving this problem, we have that the eigenvalues are
$$
\tan\lambda_n = \frac{1}{\lambda_n}.
$$
Code:
Nmax = 40;
MyTime = Table[t, {t, 0.0001, 4, .2}];
f[x_] = 1;
Plot[{Tan[x] , 1/x}, {x, 0, 5 Pi}]
Here we can look at the plot of the solution to $\tan\lambda_n = \frac{1}{\lambda_n}$.
View attachment 367
Now, let's find the first 40 eigenvalues numerically.
Code:
\[Lambda] = Flatten[Table[FindRoot[Tan[x] - 1/x == 0, {x, (n - 1/2)*\[Pi] - 0.0001}], {n, Nmax}]][[All, 2]]

{0.860334, 3.42562, 6.4373, 9.52933, 12.6453, 15.7713, 18.9024, 
22.0365, 25.1724, 28.3096, 31.4477, 34.5864, 37.7256, 40.8652, 
44.005, 47.1451, 50.2854, 53.4258, 56.5663, 59.707, 62.8478, 65.9886, 
69.1295, 72.2705, 75.4115, 78.5525, 81.6936, 84.8348, 87.976, 
91.1172, 94.2584, 97.3996, 100.541, 103.682, 106.824, 109.965, 
113.106, 116.248, 119.389, 122.53}
Let's setup the rest of our problem now so we can produces the plots and obtain the coefficients of the first 40 terms.
Code:
A = Table[2*Integrate[f[x]*Cos[\[Lambda][[n]]*x], {x, 0, 1}], {n, 1, Nmax}]

{1.76225, -0.163604, 0.0476919, -0.0219042, 0.0124686, -0.00802462, 
0.0055897, -0.00411432, 0.00315382, -0.00249397, 0.00202131, 
-0.00167123, 0.00140477, -0.00119727, 0.00103256, -0.00089962, 
0.00079079, -0.000700571, 0.000624951, -0.000560943, 0.000506285, 
-0.000459243, 0.000418464, -0.000382884, 0.000351655, -0.000324096, 
0.000299655, -0.000277877, 0.000258389, -0.000240882, 0.000225095, 
-0.000210811, 0.000197844, -0.000186038, 0.000175258, -0.000165388, 
0.000156329, -0.000147995, 0.000140309, -0.000133208}

u[x_, t_] = Sum[A[[n]]*Cos[\[Lambda][[n]]*x]*E^{-\[Lambda][[n]]^2*t}, {n, 1, Nmax}];

Plot[u[x, MyTime], {x, 0, L}, PlotStyle -> {Red}]
View attachment 368
Let's produce our density plot
Code:
DensityPlot[u[x, y], {x, 0, 1}, {y, 0, 1}, PlotRange -> All, ColorFunction -> "Rainbow"]
View attachment 369
Next is our 3d plot
Code:
Plot3D[u[x, y], {x, 0, 1}, {y, 0, 1}, PlotRange -> All, Boxed -> False, ColorFunction -> "Rainbow"]
View attachment 370
Finally, we have the contour plot
Code:
ContourPlot[u[x, y], {x, 0, 1}, {y, 0, 1}, PlotRange -> All, ColorFunction -> "Rainbow"]
View attachment 371
 
Attachments
  • Plot of tan(x) curves with asterisk-free periodic vertical asymptotes alongside a decaying curve 1/x, x from 0 to about 16, y from -2.5 to 3, showing intersections of tan x and 1/x.
    tanv1overlambda.jpg
    9.3 KB · Views: 148
  • Family of red curves on x from 0 to about 3.2 and y from -1.5 to 1.5, starting at different heights near x = 0 and converging toward a crossing near x = 1.8, then fanning downward past it.
    thalfstep.jpg
    11.5 KB · Views: 146
  • Color contour plot over the unit square, x and y axes from 0 to 1, with a rainbow colormap: red-orange across most of the domain, shading to yellow-green and blue in the upper-right corner.
    density2chw3.jpg
    9.7 KB · Views: 146
  • 3D surface plot of temperature T(x,t) over x from 0 to 1 and time from 0 to 1, colored with a rainbow gradient, showing temperature decreasing from about 1.00 toward 0.90 as the surface slopes down toward the boundary.
    3dPlot2hw3.jpg
    18.1 KB · Views: 156
  • Contour plot over the unit square of a temperature field, with colour bands from orange at the bottom through yellow, green and blue to purple at the upper right, plus a thin red noisy strip along the bottom edge.
    contour2chw3.jpg
    12 KB · Views: 143
Last edited:
Consider Laplace's equation $\nabla^2u = 0$ on the rectangle with the following boundary conditions:
$$
u_y(x,0) = f(x)\quad u(L,y) = 0\quad u(x,H) = 0\quad u(0,y) = g(y).
$$
Evaluate the series coefficients for the particular case of $f(x) = g(y) = 1$ and plot a contour map of $u(x,y)$ assuming $L = H = 1$.
So the solution is
$$
u(x,y) = \frac{4}{\pi}\sum_{n = 1}^{\infty}\left[\frac{\sin(2n - 1)\pi x\sinh\left[\pi(2n - 1) (1 - y)\right]}{\pi(2n - 1)^2\sinh\left[(2n - 1)\pi\right]} + \frac{\sin(2n - 1)\pi y\sinh\left[(2n - 1)\pi(1 - x)\right]}{(2n - 1)\sinh\left[(2n - 1)\pi\right]}\right].
$$
Let's use Mathematica to produce the desired plots.
Code:
Nmax = 40;
L = 1;
H = 1;
\[Lambda] = Table[(n*Pi)/L, {n, 1, Nmax}];

f[x_] = 1;
g[y_] = 1;A = Table[2/(L*\[Lambda][[n]]*Cosh[\[Lambda][[n]]*H])*Integrate[f[x]*Sin[\[Lambda][[n]]*x], {x, 0, L}], {n, 1, Nmax}];
B = Table[2/(L*Sinh[\[Lambda][[n]]*H])*Integrate[g[y]*Sin[\[Lambda][[n]]*y], {y, 0, H}], {n, 1, Nmax}];

u[x_, y_] = Sum[A[[n]]*Sin[\[Lambda][[n]]*x]*Sinh[\[Lambda][[n]]*(H - y)] + B[[n]]*Sin[\[Lambda][[n]]*y]*Sinh[\[Lambda][[n]]*(L - x)], {n, 1, Nmax}];

DensityPlot[u[x, y], {x, 0, L}, {y, 0, H}, PlotRange -> All, ColorFunction -> "Rainbow"]
View attachment 372
Code:
Plot3D[u[x, y], {x, 0, L}, {y, 0, H}, PlotRange -> All, Boxed -> False, ColorFunction -> "Rainbow"]
View attachment 373
Code:
ContourPlot[u[x, y], {x, 0, L}, {y, 0, H}, PlotRange -> All, ColorFunction -> "Rainbow"]
View attachment 374
 
Attachments
  • Density plot on the unit square of u(x,y) with a rainbow colour map: red at the left edge (x = 0) fading through yellow and green to blue along the top and right edges.
    density3bhw3.jpg
    9.7 KB · Views: 145
  • 3D surface plot of u(x,y) over the unit square, rendered in a rainbow color map with a mesh; the surface is high near x=0 and falls to zero along x=1 and y=1.
    3dPlot3bhw3.jpg
    11.3 KB · Views: 143
  • Filled contour plot over the unit square of a function u(x,y), with bands of colour from red and orange near the left edge through yellow and green to blue near the top and right edges, where the contours bunch close together.
    contour3bhw3.jpg
    12.1 KB · Views: 145
Let's consider the problem we just did. What if $f(x)$ was defined

Code:
Nmax = 40;
L = 1;
H = 1;
\[Lambda] = Table[(n*Pi)/L, {n, 1, Nmax}];

f[x_] = Piecewise[{{1, x < L/2}, {0, x > L/2}}];
g[y_] = 1;A = Table[2/(L*\[Lambda][[n]]*Cosh[\[Lambda][[n]]*H])*Integrate[f[x]*Sin[\[Lambda][[n]]*x], {x, 0, L}], {n, 1, Nmax}];
B = Table[2/(L*Sinh[\[Lambda][[n]]*H])*Integrate[g[y]*Sin[\[Lambda][[n]]*y], {y, 0, H}], {n, 1, Nmax}];

u[x_, y_] = Sum[A[[n]]*Sin[\[Lambda][[n]]*x]*Sinh[\[Lambda][[n]]*(H - y)] + B[[n]]*Sin[\[Lambda][[n]]*y]*Sinh[\[Lambda][[n]]*(L - x)], {n, 1, Nmax}];

DensityPlot[u[x, y], {x, 0, L}, {y, 0, H}, PlotRange -> All, ColorFunction -> "Rainbow"]
View attachment 375
Code:
Plot3D[u[x, y], {x, 0, L}, {y, 0, H}, PlotRange -> All, Boxed -> False, ColorFunction -> "Rainbow"]
View attachment 376
Code:
ContourPlot[u[x, y], {x, 0, L}, {y, 0, H}, PlotRange -> All, ColorFunction -> "Rainbow"]
View attachment 377
 
Attachments
  • Density plot on a unit square with a rainbow colour map, orange at the left edge fading through green and blue to purple at the right edge, with the lower-left corner showing a sharp colour change.
    density3hw3piecewise.jpg
    10.7 KB · Views: 121
  • 3D surface plot from Mathematica of a temperature-like field u(x, y) over a unit square, with a steep ridge rising along the x = 0 edge and falling smoothly to near zero toward the far edges, coloured with a rainbow gradient.
    3dPlot3hw3piecewise.jpg
    22.3 KB · Views: 142
  • Filled contour plot on a unit square in rainbow colours, with orange bands near the left edge fading to purple across the right side; contours curve toward the left edge.
    contour3hw3piecewise.jpg
    11.9 KB · Views: 150