mathematica appendix to lectures on pdes: part 2 (problems...
TRANSCRIPT
![Page 1: Mathematica appendix to lectures on PDEs: part 2 (problems ...courses.washington.edu/ph227814/228/nb/PDE2.nb.pdf“ParallelTable” so that each core of my computer is making plots](https://reader033.vdocuments.site/reader033/viewer/2022052003/6015c8685a6ed57a81551c6b/html5/thumbnails/1.jpg)
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}]
Out[40]=
0.0 0.2 0.4 0.6 0.8 1.0r0.0
0.2
0.4
0.6
0.8
1.0T
Radial Temp distribution at z=0, 0.05, 0.1 and 0.5
00.050.10.05
3D plot of T vs (x,y), using ParametricPlot3D to restrict plot to the region of the cylinder.
![Page 2: Mathematica appendix to lectures on PDEs: part 2 (problems ...courses.washington.edu/ph227814/228/nb/PDE2.nb.pdf“ParallelTable” so that each core of my computer is making plots](https://reader033.vdocuments.site/reader033/viewer/2022052003/6015c8685a6ed57a81551c6b/html5/thumbnails/2.jpg)
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 preren-der 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.
2 RevisedPDE2.nb
![Page 3: Mathematica appendix to lectures on PDEs: part 2 (problems ...courses.washington.edu/ph227814/228/nb/PDE2.nb.pdf“ParallelTable” so that each core of my computer is making plots](https://reader033.vdocuments.site/reader033/viewer/2022052003/6015c8685a6ed57a81551c6b/html5/thumbnails/3.jpg)
In[43]:= Manipulate[VaryZFrames[[i]], {i, 1, 10, 1}]
Out[43]=
i
7
This is how you plot just a “wedge” of the solution, which is useful for HW10 plots
RevisedPDE2.nb 3
![Page 4: Mathematica appendix to lectures on PDEs: part 2 (problems ...courses.washington.edu/ph227814/228/nb/PDE2.nb.pdf“ParallelTable” so that each core of my computer is making plots](https://reader033.vdocuments.site/reader033/viewer/2022052003/6015c8685a6ed57a81551c6b/html5/thumbnails/4.jpg)
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 #1Steady 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]:= Expand[tt1371[1, theta]]
Out[46]= 35 Cos[theta]4
Plotting T vs θ𝜃 at various radii:
4 RevisedPDE2.nb
![Page 5: Mathematica appendix to lectures on PDEs: part 2 (problems ...courses.washington.edu/ph227814/228/nb/PDE2.nb.pdf“ParallelTable” so that each core of my computer is making plots](https://reader033.vdocuments.site/reader033/viewer/2022052003/6015c8685a6ed57a81551c6b/html5/thumbnails/5.jpg)
In[47]:= 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}]
Out[47]=
π𝜋8
π𝜋4
3π𝜋8
π𝜋2
5π𝜋8
3π𝜋4
7π𝜋8
π𝜋θ𝜃
10
20
30
TT vs θ𝜃 (r=0, 1/∕4, 1/∕2, 3/∕4 & 1)
00.250.50.751
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 tempera-ture at a given {θ𝜃,ϕ𝜑} point, not the actual radius.
RevisedPDE2.nb 5
![Page 6: Mathematica appendix to lectures on PDEs: part 2 (problems ...courses.washington.edu/ph227814/228/nb/PDE2.nb.pdf“ParallelTable” so that each core of my computer is making plots](https://reader033.vdocuments.site/reader033/viewer/2022052003/6015c8685a6ed57a81551c6b/html5/thumbnails/6.jpg)
In[49]:= ManipulateSphericalPlot3Dtt1371[r, th], {th, 0, Pi},ϕ, 0, 3 Pi 2, PlotRange → {{-−10, 10}, {-−10, 10}, Automatic}, {r, 1, 0}
Out[49]=
r
0.0923346
6 RevisedPDE2.nb