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

In summary, the conversation discusses various problems involving the transient heating of a slab and the diffusion of heat in a 1-D slab. The problems involve the usual 1-D heat equation with mixed boundary conditions. The solutions to these problems are obtained using mathematical techniques and plotted using Mathematica. The problems include finding the solution for a particular case with given boundary conditions, constructing various plots to visualize the process, and evaluating series coefficients for a rectangle with specific boundary conditions.
  • #1
Dustinsfl
2,281
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

  • plotseries1hw3.jpg
    plotseries1hw3.jpg
    11.9 KB · Views: 87
  • 3dplot1hw3.jpg
    3dplot1hw3.jpg
    17.8 KB · Views: 84
  • density1hw3.jpg
    density1hw3.jpg
    11.5 KB · Views: 77
  • contour1hw3.jpg
    contour1hw3.jpg
    13.1 KB · Views: 79
Last edited:
Physics news on Phys.org
  • #2
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

  • tanv1overlambda.jpg
    tanv1overlambda.jpg
    9.3 KB · Views: 82
  • thalfstep.jpg
    thalfstep.jpg
    11.5 KB · Views: 79
  • density2chw3.jpg
    density2chw3.jpg
    9.7 KB · Views: 77
  • 3dPlot2hw3.jpg
    3dPlot2hw3.jpg
    18.1 KB · Views: 83
  • contour2chw3.jpg
    contour2chw3.jpg
    12 KB · Views: 74
Last edited:
  • #3
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

  • density3bhw3.jpg
    density3bhw3.jpg
    9.7 KB · Views: 74
  • 3dPlot3bhw3.jpg
    3dPlot3bhw3.jpg
    11.3 KB · Views: 87
  • contour3bhw3.jpg
    contour3bhw3.jpg
    12.1 KB · Views: 66
  • #4
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

  • density3hw3piecewise.jpg
    density3hw3piecewise.jpg
    10.7 KB · Views: 60
  • 3dPlot3hw3piecewise.jpg
    3dPlot3hw3piecewise.jpg
    22.3 KB · Views: 75
  • contour3hw3piecewise.jpg
    contour3hw3piecewise.jpg
    11.9 KB · Views: 78
  • #5
Overall, using Mathematica to plot PDEs is a powerful tool for visualizing and understanding complex mathematical problems. With the ability to manipulate and animate the plots, we can gain deeper insights into the behavior of the solution and its dependence on various parameters. This can greatly aid in the analysis and interpretation of the results, making Mathematica an invaluable resource for scientists and engineers. Additionally, the availability of downloadable notebooks allows for easy access and use of pre-made problems, making it a convenient and efficient tool for tackling a wide range of PDE problems.
 

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

What is Mathematica and how does it help with plotting PDEs?

Mathematica is a computer software program used for mathematical and scientific calculations. It also has powerful visualization capabilities, making it suitable for plotting PDEs (partial differential equations). It uses advanced algorithms to accurately plot and visualize the solutions to PDEs, making it a valuable tool for scientists and researchers.

What are some key features of Mathematica that make it useful for plotting PDEs?

Some key features of Mathematica that make it useful for plotting PDEs include its built-in functions for solving and visualizing PDEs, the ability to customize and manipulate plots, and the option to export plots for use in publications or presentations. It also has a user-friendly interface and extensive documentation, making it easy to learn and use.

Can Mathematica plot any type of PDE?

Yes, Mathematica has the capability to plot a wide range of PDEs, including linear and nonlinear equations, initial and boundary value problems, and systems of equations. It can also handle PDEs with variable coefficients and boundary conditions, making it a versatile tool for solving and visualizing a variety of PDEs.

What are some tips for effectively using Mathematica to plot PDEs?

Some tips for effectively using Mathematica to plot PDEs include familiarizing yourself with the syntax and built-in functions for solving and plotting PDEs, using appropriate boundary conditions and initial conditions, and experimenting with different plot options to find the most informative and visually appealing representation of the PDE solution. It is also helpful to consult the Mathematica documentation and seek assistance from online forums or communities.

Can Mathematica be used to animate PDE solutions?

Yes, Mathematica has the ability to animate the solution of PDEs over time or other variables. This can be useful for visualizing the behavior of a PDE solution and identifying key features or patterns. It can also be used for educational or presentation purposes to enhance understanding and engagement with the material.

Similar threads

Replies
2
Views
2K
Replies
1
Views
921
Replies
11
Views
3K
Replies
1
Views
828
Replies
2
Views
3K
Replies
1
Views
1K
Back
Top