A long cylinder of radius R = 0.05 m and thermal diffusivity alpha = 1.2e-5
2
m
/s is initially at a uniform temperature T0 = 100 °C. At t = 0 its surface is brought into contact with a fluid such as Tinf = 20 °C and h=100 W/
2
m
*K
. The temperature T(r, t) follows the radial heat equation dT/dt = alpha (
2
d
T/d
2
r
+ (1/r) dT/dr), with dT/dr = 0 at the axis and -k*dT/dr = h*(T-Tinf) at the surface. Three solutions are compared: (1) NDSolve (method of lines), (2) Chebyshev and Jacobi polynomial orthogonal collocation, (3) the exact series solution by separation of variables.

Solution based on NDSolve

Numerical reference solution. NDSolveValue discretizes r automatically (method of lines) and integrates in time, returning an interpolating function sol[r, t]. Results are shown as profiles, a contour map and a density map.
Model setup. Parameters are in SI units: R = cylinder radius [m], alpha = thermal diffusivity [
2
m
/s], T0 = uniform initial temperature and Tinf = bulk fluid’s temperature [°C]. The PDE is the radial heat equation for a long cylinder, dT/dt = alpha (
2
d
T/d
2
r
+ (1/r) dT/dr). Conditions: T(r,0) = T0; symmetry at the axis, dT/dr = 0; -k*dT/dr = h*(T-Tinf) at the surface for t > 0. The surface boundary condition is multiplied by (1 - Exp[-10^4 t^2]), which smoothly switches on the surface heat transfer from zero at t = 0 and removes the incompatibility between the uniform initial condition and the convection boundary condotion.The inner end of the domain is 1e-8 instead of 0 to avoid the 1/r singularity. Biot number is equal to 3.333.
In[]:=
(*Parameters*)​​R=0.05;(*cylinderradius(m)*)​​alpha=1.2*10^-5;(*thermaldiffusivity(m^2/s)*)​​T0=100;(*initialuniformtemperature(degC)*)​​k=1.5;(*thermalconductivity(W/m.K)*)​​h=100;(*convectioncoefficient(W/m^2.K)*)​​Tinf=20;(*fluidtemperature(degC)*)​​Bi=hR/k;(*Biotnumber=10/3*)​​tEnd=250;(*endtime(s):coolingtakesafewhundredsforthesevalues*)​​tShow=100;(*timeusedforthe2Dmaps(s)*)​​times={0,10,30,60,100,200};(*profiletimes(s)*)​​
In[]:=
(*Boundaryconditions*)​​(*1)axis:symmetry,dT/dr=0(r=1e-8avoidsthe1/rsingularity)*)​​(*2)surface:convection,-kdT/dr=h(T-Tinf).​​hismultipliedbytheramp(1-Exp[-10^4t^2]),whichis0att=0,​​sothattheboundaryconditionisconsistentwiththeuniforminitial​​condition(dT/dr=0att=0)andtheNDSolvewarningdisappears*)​​bc={Derivative[1,0][T][10^-8,t]==0,​​-kDerivative[1,0][T][R,t]==h(1-Exp[-10^4t^2])(T[R,t]-Tinf)};​​​​(*PDE*)​​(*Radialheatequation:dT/dt=alpha(d2T/dr2+(1/r)dT/dr)*)​​pde=D[T[r,t],t]==​​alpha*(D[T[r,t],{r,2}]+(1/r)D[T[r,t],r]);​​​​(*Initialcondition:uniformtemperatureT0*)​​ic=T[r,0]==T0;​​​​(*Solveforrin[1e-8,R],tin[0,tEnd]s;sol[r,t]isanInterpolatingFunction*)​​sol=Quiet@NDSolveValue[{pde,ic,bc},T,{r,10^-8,R},{t,0,tEnd},Method->{"MethodOfLines"},MaxStepSize->0.1,AccuracyGoal->12,PrecisionGoal->12];
Plots the NDSolve temperature profiles T(r) at the times listed in times= {0, 10, 30, 60, 100 and 200 s}.
r starts at 1e-8 to stay away from the axis singularity. The plot is stored in p so later cells can overlay other curves with Show.
In[]:=
(*RadialtemperatureprofilesT(r)fromtheNDSolvesolution*)​​(*Times(s)aresetintheparameterscell:times={0,10,30,60,100,200}*)​​p=Plot[Evaluate@Table[sol[r,t],{t,times}],{r,10^-8,R},FrameLabel->{"r (m)","T (°C)"},PlotLegends->(ToString[#]<>" s"&/@times),PlotLabel->"\nTransient Heat Conduction in a Cylinder\n",​​AspectRatio->1,PlotRange->{{0,R},{20,102}},Frame->True,GridLines->Automatic]
Out[]=
0 s
10 s
30 s
60 s
100 s
200 s
The field is axisymmetric, so the temperature at (x, y) is sol evaluated at r = Sqrt[x^2 + y^2] and t = tShow (set in the parameters cell, 100 s). Points outside the cylinder return Indeterminate (they are not drawn); Max[rr, 1e-8] keeps r inside the NDSolve domain.
In[]:=
(*temp[x,y]:temperatureatCartesianpoint(x,y)att=tShow*)​​(*rr=distancefromtheaxis;outsidethecylinder(rr>R)thevalueisIndeterminate*)​​(*Max[rr,1e-8]keepsrinsidetheNDSolvedomain,whichstartsat1e-8*)​​temp[x_,y_]:=Module[{rr=Sqrt[x^2+y^2]},​​If[rr<=R,sol[Max[rr,10^-8],tShow],Indeterminate]];
Contour map of the temperature over the circular cross-section at t = tShow = 100 s (RegionFunction masks everything outside r = R).
In[]:=
(*Contourmapofthecross-sectiontemperatureatt=100s*)​​(*RegionFunctionrestrictstheplottothediscx^2+y^2<=R^2*)​​ContourPlot[temp[x,y],{x,-R,R},{y,-R,R},RegionFunction->Function[{x,y,z},x^2+y^2<=R^2],ColorFunction->"Rainbow",ContourStyle->Opacity[0.2],PlotPoints->100,Frame->True,FrameLabel->{"x (m)","y (m)"},Contours->10,PlotLabel->"\nTemperature Distribution in Cylinder Cross Section (t = 100)\n",PlotLegends->Automatic,AspectRatio->1]
Out[]=
Density (heat) map of the same field. Same data as the contour plot, shown as a continuous color map.
In[]:=
(*Densitymapofthecross-sectiontemperatureatt=100s*)​​(*RegionFunctionrestrictstheplottothediscx^2+y^2<=R^2*)​​DensityPlot[temp[x,y],{x,-R,R},{y,-R,R},RegionFunction->Function[{x,y,z},x^2+y^2<=R^2],ColorFunction->"Rainbow",PlotPoints->100,Frame->True,FrameLabel->{"x (m)","y (m)"},PlotLabel->"\nTemperature Distribution in Cylinder Cross Section (t = 100)\n",PlotLegends->Automatic,AspectRatio->1]
Out[]=

Solution based on Chebyshev Orthogonal Collocation

Pseudo-spectral (collocation) solution. The radius is discretized at Chebyshev-Gauss-Lobatto nodes mapped to [0, R], derivatives become differentiation matrices, and the PDE reduces to ODEs in time for the nodal temperatures. The first part uses Chebyshev nodes (Np = 20); the second part uses orthogonal collocation with polynomials in
2
r
(Np = 11). Both are overlaid as gray dots on the NDSolve curves.
Np = number of collocation intervals (Np = 20), giving Np+1 = 21 collocation points. The error decreases as Np increases.
In[]:=
(*Np=numberofcollocationintervals(Np+1nodes)*)​​Np=20;
Corner entry D[0,0] of the differentiation matrix. The four corners, the diagonal, the edges and the interior each obey a different closed-form expression, so they are defined case by case below.
Chebyshev differentiation matrix d[i,j] for the Gauss-Lobatto nodes
y
i
= Cos[i π/Np], i,j = 0..Np. The next cells define every entry: the two corner diagonals (+/-(2 Np^2 + 1)/6), the interior diagonal, the interior off-diagonal terms and the first/last rows and columns, which carry the factor c_i/c_j with c_0 = c_Np = 2 and c = 1 elsewhere.
In[]:=
(*Differentiationmatrixentryd[0,0]=(2Np^2+1)/6*)​​d[0,0]=(2Np^2+1)/6//N;
Opposite corner entry D[Np,Np] = -D[0,0] (the matrix is centro-antisymmetric).
In[]:=
(*Differentiationmatrixentryd[Np,Np]=-(2Np^2+1)/6(oppositecorner)*)​​d[Np,Np]=-(2Np^2+1)/6//N;
Diagonal entries for the interior nodes (0 < i < Np).
Off-diagonal entries D[j,k] for interior rows and columns, j != k. The alternating sign (-1)^(j+k) and the node spacing y[j]-y[k] come from differentiating the Lagrange cardinal polynomials at the grid points.
Remaining corner entry D[Np,0].
Remaining corner entry D[0,Np].
First column: interior rows j, column 0.
Last column: interior rows j, column Np.
First row: row 0, interior columns j. Note the factor 2 -- the boundary rows carry the Chebyshev weight c_0 = c_Np = 2 while interior nodes have c = 1.
Last row: row Np, interior columns j.
Assemble all of the above into Add, the (Np+1)x(Np+1) first-derivative operator. Multiplying a vector of nodal values by Add returns the vector of first derivatives at those nodes.
Assemble the (Np+1) x (Np+1) first-derivative matrix Add from the entries above; Add.T gives d/dy at the nodes. Bdd = Add.Add is then the second-derivative matrix.
The second-derivative operator is simply the first-derivative matrix applied twice: Bdd = Add . Add.
Chebyshev collocation solution of the same two-component problem (method of lines). The first-derivative matrix Add and the second-derivative matrix Bdd defined above are mapped from y in [-1,1] to r in [0,1] and used to discretise dc/dr and d2c/dr2.
Radial positions of the nodes. The map r = R (1 + y)/2 sends y = 1 to the surface r = R (first node) and y = -1 to the axis r = 0 (last node). Because dr = (R/2) dy, derivatives pick up factors of 2/R (first) and (2/R)^2 (second).
Semi-discrete heat equation at node i. Each derivative in the PDE is replaced by a matrix-vector product: dT/dr → (2/R) Add.T, d2T/dr2 → (2/R)^2 Bdd.T,
dT/dt → T[i]'[t]. The result is one ODE in time for every node T[i][t].
Boundary conditions. At the axis (last node) the symmetry condition dT/dr = 0 is imposed with the derivative matrix row Np+1. At the surface (first node) the boundary condition is: -k*dT/dr = h*(T-Tinf).
The equations are assembled into one system: the PDE at the interior nodes i = 2..Np, the two boundary conditions and the initial conditions. The first and last nodes are fixed by the boundary conditions, so the problem is a differential-algebraic system. Note that T[1][0] = T0 and T[1][t] = Ts are inconsistent at t = 0; NDSolve may issue a message and re-initialize.
Overlay of the collocation solution (gray dots at the Np+1 nodes) on the NDSolve curves p, for the six times in tk.

Solution based on Classic Orthogonal Collocation for symmetrical problems (Jacobi Polynomials)

We choose 11 internal collocation points (N=11). The code could be changed in order to consider larger numbers of collocation points.
Matrix C
First-derivative matrix in the monomial basis: d/dx of x^(2i-2) is (2i-2) x^(2i-3).
Matrix A
In[]:=
A=Ci.IQ
Matrix D
Matrix B
In[]:=
B=Di.IQ
Semi-discrete equations for the polynomial collocation. The PDE is written in x = r/R, so alpha is divided by R^2. The matrix B replaces the whole Laplacian (second derivative and 1/x term), which is why the 1/r term does not appear explicitly. The matrix A is defined in the rules but not needed here.
Plot of the NDSolve profiles against r/R. This redefines p (previously in r, meters), so the next Show overlays the collocation nodes (in r/R) correctly.
Overlay of the polynomial-collocation nodes (gray dots) on the NDSolve profiles.

Analytical Solution based on separation of variables