Mathematica appendix to lectures on PDEs: part 1 (Cartesian variables) Example problem Sec 13.2 #2 Checking Fourier series representation of temperature along lower edge. In[853]:= In[854]:= Clear@LLD; LL = 20; Tlower@nmax_, x_D := Sum@Sin@ Pi n x ê LLD 200 HCos@n Pi ê 2D - Cos@n PiDL ê HPi nL, 8n, 1, nmax<D Showing the convergence of the Fourier series with nmax=3, 10 and 100: In[855]:= Plot@8Tlower@3, xD, Tlower@10, xD, Tlower@100, xD<, 8x, 0, LL<, AxesLabel Ø 8x, T<, PlotStyle Ø 88Thick, Black<, 8Thick, Blue<, 8Thick, Red<<D T 120 100 80 Out[855]= 60 40 20 x 5 10 15 20 Here’s the full result, with the sum truncated at nmax terms: In[856]:= ttfull@nmax_, x_, y_D := Sum@ Exp@- n Pi y ê LLD Sin@ Pi n x ê LLD 200 HCos@n Pi ê 2D - Cos@n PiDL ê HPi nL, 8n, 1, nmax<D Here’s a “3D plot” showing the temperature with nmax=100. Note that the temperature distribution smooths out quickly at y increases, since the higher harmonics damp most quickly. 2 PDE1.nb In[857]:= Plot3D@ttfull@100, x, yD, 8x, 0, LL<, 8y, 0, 2 LL<, AxesLabel Ø 8x, y<, PlotRange Ø 8- 20, 120<, PlotLabel Ø "THx,yL"D Out[857]= This plot shows cross sections as y increases, showing the smoothness and the decay of the temperature: In[858]:= Plot@8ttfull@200, x, 1D, ttfull@200, x, 5D, ttfull@200, x, 10D, ttfull@200, x, 20D<, 8x, 0, LL<, AxesLabel Ø 8x, T<, PlotLabel Ø "Temp profile at y=1, 5, 10 and 20"D Temp profile at y=1, 5, 10 and 20 T 80 60 Out[858]= 40 20 x 5 10 15 20 This plot shows how, for y=5, only nmax =10 is needed PDE1.nb In[859]:= Plot@8ttfull@2, x, 5D, ttfull@10, x, 5D, ttfull@50, x, 5D, ttfull@100, x, 5D<, 8x, 0, LL<, AxesLabel Ø 8x, T<, PlotStyle Ø 88Thick, Black<, 8Thick, Blue<, 8Thick, Red<, 8Thick, Green<<, PlotLabel Ø "Temp profile at y=5 for nmax=2, 10, 50, 100"D Temp profile at y=5 for nmax=2, 10, 50, 100 T 35 30 25 Out[859]= 20 15 10 5 x 5 10 15 20 Sec 13.3 #5 Here’s the plot of time dependence, with alpha=1, and using nmax=100 In[862]:= In[866]:= uu5@nmax_, x_, t_D := 100 + Sum@Exp@- HH2 n - 1L Pi ê 2L ^ 2 tD HSin@H2 n - 1L Pi ê 2D - H2 n - 1L Pi ê 2L Sin@H2 n - 1L Pi x ê 2D 800 ê HPi H2 n - 1LL ^ 2, 8n, 1, nmax<D Plot3D@uu5@100, x, tD, 8x, 0, 2<, 8t, 0, 1<, AxesLabel Ø 8x, t<, PlotRange Ø 80, 100<D Out[866]= Sec. 13.4 #4 Here is the result (with v=h=l=1) 3 4 PDE1.nb In[867]:= yy4@nmax_, x_, t_D := Sum@16 H2 Sin@n Pi ê 8D - Sin@n Pi ê 4DL Sin@n Pi xD Cos@n Pi tD ê Hn PiL ^ 2, 8n, 1, nmax<D Here is the string shape at t=0---checking that the Fourier series coefficients are correct: In[868]:= Plot@yy4@100, x, 0D, 8x, 0, 1<, AxesLabel Ø 8x, y<, PlotStyle Ø 8Thick, Red<, PlotLabel Ø "t=0", PlotRange Ø 8- 1, 1<D t=0 y 1.0 0.5 Out[868]= x 0.2 0.4 0.6 0.8 1.0 -0.5 -1.0 This animation shows the motion of the string for one full cycle We see that this is nothing other than a travelling wave bouncing off the ends. In[869]:= Animate@Plot@yy4@100, x, tD, 8x, 0, 1<, AxesLabel Ø 8x, y<, PlotRange Ø 8- 1, 1<, PlotStyle Ø 8Thick, Red<, PlotLabel Ø tD, 8t, 0, 2<, AnimationRate Ø 0.05D t 1.54808 y 1.0 0.5 Out[869]= x 0.2 -0.5 -1.0 0.4 0.6 0.8 1.0
© Copyright 2026 Paperzz