Mathematica appendix to lectures on PDEs:
part 2 (problems using cylindrical and spherical coords)
Sec. 13.5 #2(b)
Semi-infinite cylinder of radius a (taken to be 1 here) with T=0 on rounded
surface and at infinity and T=r sin ΞΈπ on bottom (z=0)
Use tables to speed up computation:
first the first 100 zeroes of J_1
In[38]:=
zeroJ1 = Table[BesselJZero[1, n], {n, 1, 100}] /β/β N;
Here is the sum of the first 100 terms contributing to the r and z dependence (with the overall sin ΞΈπ
factor pulled out)
Total just adds up the entries of the array:
In[39]:=
tt1352[r_, z_] =
Total[(2 /β zeroJ1) (BesselJ[1, zeroJ1 r] /β BesselJ[2, zeroJ1]) Exp[-β zeroJ1 z]];
In[40]:=
Plot[{tt1352[r, 0], tt1352[r, 0.05], tt1352[r, 0.1], tt1352[r, 0.5]}, {r, 0, 1},
AxesLabel βο·οο’ {r, T}, PlotRange βο·οο’ {{0, 1}, {0, 1}}, PlotStyle βο·οο’ {Thick},
PlotLabel βο·οο’ "Radial Temp distribution at z=0, 0.05, 0.1 and 0.5",
PlotLegends βο·οο’ {0, 0.05, 0.1, 0.05}]
T
Radial Temp distribution at z=0, 0.05, 0.1 and 0.5
1.0
0.8
0
0.05
0.6
Out[40]=
0.1
0.4
0.05
0.2
0.0
0.0
0.2
0.4
0.6
0.8
1.0
r
3D plot of T vs (x,y), using ParametricPlot3D to restrict plot to the region of the cylinder.
2
RevisedPDE2.nb
In[41]:=
ParametricPlot3D[{r Cos[theta], r Sin[theta], tt1352[r, 0.5] Sin[theta]},
{r, 0, 1}, {theta, 0, 2 Pi}, AxesLabel βο·οο’ {"x", "y", "T"},
PlotLabel βο·οο’ "T at z=0.5", BoxRatios βο·οο’ {1, 1, 1}]
Out[41]=
Lets see how this changes with z. Each plot takes a non-trivial amount of time to generate, lets prerender them. Iβm making sure to specify PlotRange here so they are all scaled the same. Iβm also using
βParallelTableβ so that each core of my computer is making plots. This sped it up on my personal laptop
by a factor of 2, this wonβt always make things faster depending on your individual machine. If you are
curious, try running it both ways (using Table and ParallelTable) inside the function AbsoluteTiming[ ].
In[42]:=
VaryZFrames = ParallelTable[ParametricPlot3D[
{r Cos[theta], r Sin[theta], tt1352[r, z] Sin[theta]}, {r, 0, 1}, {theta, 0, 2 Pi},
AxesLabel βο·οο’ {"x", "y", "T"}, PlotLabel βο·οο’ StringForm["T at z=``", z],
BoxRatios βο·οο’ {1, 1, 1}, PlotRange βο·οο’ {{-β 1, 1}, {-β 1, 1}, {-β 1, 1}}], {z, 0, 1, .1}];
StringForm is a function that makes the second argument into a string and puts it where the ``s are.
RevisedPDE2.nb
In[43]:=
Manipulate[VaryZFrames[[i]], {i, 1, 10, 1}]
i
7
Out[43]=
This is how you plot just a βwedgeβ of the solution, which is useful for HW10 plots
3
4
RevisedPDE2.nb
In[44]:=
ParametricPlot3Dο{r Cos[theta], r Sin[theta], tt1352[r, 0.5] Sin[theta]},
{r, 0, 1}, οtheta, Pi ο 3, 2 Pi ο 3ο§, AxesLabel βο·οο’ {x, y, "T"},
PlotLabel βο·οο’ "T at z=0.5", BoxRatios βο·οο’ {1, 1, 1}ο
Out[44]=
β Sec. 13.7 #1
Steady state temp in a sphere of radius 1 if surface temp is 35 cos^4 ΞΈπ
Here's the solution
In[45]:=
tt1371[r_, theta_] =
7 + 20 r ^ 2 LegendreP[2, Cos[theta]] + 8 r ^ 4 LegendreP[4, Cos[theta]];
Checking the BC
In[46]:=
Out[46]=
Expand[tt1371[1, theta]]
35 Cos[theta]4
Plotting T vs ΞΈπ at various radii:
RevisedPDE2.nb
In[47]:=
5
Plot[{tt1371[0, th], tt1371[0.25, th], tt1371[0.5, th],
tt1371[0.75, th], tt1371[1, th]}, {th, 0, Pi}, PlotRange βο·οο’ {-β 5, 35},
Ticks βο·οο’ {Table[n *β Ο /β 8, {n, 0, 16}], Automatic}, AxesLabel βο·οο’ {"ΞΈ", "T"},
PlotLabel -β> "T vs ΞΈ (r=0, 1/β4, 1/β2, 3/β4 & 1)",
PlotStyle βο·οο’ {Thick}, PlotLegends βο·οο’ {0, .25, .5, .75, 1}]
T vs ΞΈπ (r=0, 1/β4, 1/β2, 3/β4 & 1)
T
30
0
0.25
20
0.5
Out[47]=
0.75
10
1
Οπ
Οπ
3 Οπ
Οπ
5 Οπ
3 Οπ
7 Οπ
8
4
8
2
8
4
8
ΞΈπ
Οπ
A fancier way of plotting (here for r=0.5 and 1):
In[48]:=
SphericalPlot3Dο{tt1371[0.5, th], tt1371[1, th]}, {th, 0, Pi}, οΟ, 0, 3 Pi ο 2ο§ο
Out[48]=
Here we can vary r to look at the the angular distribution. The βradiusβ in the plot represents the temperature at a given {ΞΈπ,Οπ} point, not the actual radius.
6
RevisedPDE2.nb
In[49]:=
ManipulateοSphericalPlot3Dοtt1371[r, th], {th, 0, Pi},
οΟ, 0, 3 Pi ο 2ο§, PlotRange βο·οο’ {{-β 10, 10}, {-β 10, 10}, Automatic}ο, {r, 1, 0}ο
r
0.0923346
Out[49]=
© Copyright 2026 Paperzz