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 to Ts = 20 °C. 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. 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 Ts = surface 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; surface held at Ts for t > 0. The surface value is switched from T0 to Ts with Exp[-1000
2
t
] (a smooth, almost instantaneous step) so that the initial and boundary conditions are compatible. The inner end of the domain is 1e-8 instead of 0 to avoid the 1/r singularity.
In[]:=
(*Parameters*)​​(*CylinderradiusR(m)*)​​R=0.05;​​(*Thermaldiffusivityalpha(m^2/s)*)​​alpha=1.2*10^-5;​​​​(*InitialuniformtemperatureT0(degC)*)​​T0=100;​​(*SurfacetemperatureTsfort>0(degC)*)​​Ts=20;​​​​(*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;​​​​(*BC1:symmetryattheaxis,dT/dr=0(r=1e-8avoids1/rsingularity)*)​​bc={Derivative[1,0][T][10^-8,t]==0,T[R,t]==Ts+(T0-Ts)Exp[-1000t^2]};​​​​(*Solveforrin[1e-8,R],tin[0,40]s;sol[r,t]isanInterpolatingFunction*)​​sol=NDSolveValue[{pde,ic,bc},T,{r,10^-8,R},{t,0,40}];
Plots the NDSolve temperature profiles T(r) at t = 0, 2, 6, 12, 24 and 40 s. The times are written as {0,100,300,600,1200,2000}/50 to match the legend. r starts at 1e-8 to stay away from the axis singularity. The plot is stored in p so later cells can overlay the collocation points and the analytical curves with Show.
In[]:=
(*RadialtemperatureprofilesT(r)fromtheNDSolvesolution*)​​(*Times(s):{0,100,300,600,1200,2000}/50={0,2,6,12,24,40}*)​​(*TheplotisstoredinpandoverlaidlaterwithShow*)​​(*Temperatureprofiles*)​​p=Plot[Evaluate@Table[sol[r,t],{t,{0,100,300,600,1200,2000}/50}],{r,10^-8,R},FrameLabel->{"r (m)","T (°C)"},PlotLegends->{"0","2","6","12","24","40"},PlotLabel->"\nTransient Heat Conduction in a Cylinder\n",AspectRatio->1,PlotRange->{{0,0.05},{20,102}},Frame->True,GridLines->Automatic]
Out[]=
0
2
6
12
24
40
Helper function for 2D maps. The field is axisymmetric, so the temperature at (x, y) is sol evaluated at r = Sqrt[
2
x
+
2
y
] and t = 24 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=24s*)​​(*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],24],Indeterminate]];
Contour map of the temperature over the circular cross-section at t = 24 s (RegionFunction masks everything outside r = R).
In[]:=
(*Contourmapofthecross-sectiontemperatureatt=24s*)​​(*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)"},PlotLabel->"\nTemperature Distribution in Cylinder Cross Section (t = 24)\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=24s*)​​(*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 = 24)\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;
Chebyshev-Gauss-Lobatto collocation points
y
i
= Cos[i π/Np]. These run from y = 1 (i = 0) down to y = -1 (i = Np) and cluster near the two ends, which is what suppresses the oscillations a uniform grid would produce.
In[]:=
(*Chebyshev-Gauss-Lobattonodesy_i=Cos[iPi/Np]on[-1,1];y_0=1andy_Np=-1*)​​y[i_]:=Cos[iPi/Np]//N;
Diagonal entries for the interior nodes (0 < i < Np).
In[]:=
(*Diagonalentriesforinteriornodes:d[i,i]=-y_i/(2(1-y_i^2))*)​​d[i_,i_]:=-y[i]/(2(1-y[i]^2))//N;
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 temperature is set to Ts.
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

Eigenvalues λn of the series solution: the positive zeros of the Bessel function J0, λn = BesselJZero[0, n].
Fourier numbers Fo = alpha t/R^2 for the times in tk.
Analytical profiles converted back to temperature, T = Ts + (T0 - Ts) theta, and drawn as dashed black curves. Fo = 0 is dropped (Drop[Fon, 1]) because the series does not converge at the initial instant. p2 is stored for the overlay.
Final comparison: NDSolve curves p (in r/R) with the analytical profiles p2 (dashed black) on the same axes.