Course Test · University: upper level

Fourier analysis and transforms: RatMath answers

The same twenty exercises, answered with RatMath Core and the Shelf libraries only. The code below was run when this page was built; its output is shown as printed, and compared with the independent answer.

Agrees 20

Libraries used here: core, analytic, symbolic. In this code each library is in scope under its own name (linalg.det, stats.tTest), and Core's names (R, Rational, …) are in scope directly.

  1. 1.Square waveAgrees
    Find the Fourier series of the square wave f=−1f = -1 on (−1,0)(-1, 0), f=1f = 1 on (0,1)(0, 1), period 2, up to sin⁡3πx\sin 3\pi x.
    Independent answer
    ff is odd, so only sines: bn=2∫01sin⁡nπx dx=2(1−(−1)n)nπb_n = 2\int_0^1 \sin n\pi x\,dx = \dfrac{2(1 - (-1)^n)}{n\pi}, i.e. 4nπ\dfrac{4}{n\pi} for odd nn. f∼4π(sin⁡πx+13sin⁡3πx+⋯ )f \sim \dfrac4\pi\left(\sin\pi x + \tfrac13\sin3\pi x + \cdots\right), with 4π≈1.27324\tfrac4\pi \approx 1.27324.
    RatMath code
    const F = analytic.fourier("-1 if -1:x:!0; 1 if 0:x:1", [-1, 1], { terms: 3 }).exact();
    [F.b[1], F.b[2], F.b[3]]
    Output
    [1.273239544735[14738003:25132866], -0.00000000000005197431:0.00000000000005197431, 0.4244131815[6729961113:9764525427]]
    Intervals must have rational ends, so the textbook [−π,π][-\pi, \pi] cannot be used (fourier("x", ["-pi", "pi"]) is refused); the course's period-2 versions are used instead.
  2. 2.SawtoothAgrees
    Find the Fourier coefficients of f(x)=xf(x) = x on (−1,1)(-1, 1).
    Independent answer
    Odd: bn=2∫01xsin⁡nπx dx=2(−1)n+1nπb_n = 2\int_0^1 x\sin n\pi x\,dx = \dfrac{2(-1)^{n+1}}{n\pi}: 2π,−1π,23π\tfrac2\pi, -\tfrac1\pi, \tfrac2{3\pi}.
    RatMath code
    const F = analytic.fourier("x", [-1, 1], { terms: 3 }).exact();
    [F.a[0], F.b[1], F.b[2], F.b[3]]
    Output
    [0, 0.6366197723673420749:0.63661977236785727944, -0.318309886183[93513651:66454066], 0.21220659076495164542:0.2122065908071321605]
  3. 3.ParabolaAgrees
    Find the Fourier series of f(x)=x2f(x) = x^2 on (−1,1)(-1, 1) up to cos⁡2πx\cos 2\pi x.
    Independent answer
    Even: a02=∫01x2=13\tfrac{a_0}2 = \int_0^1 x^2 = \tfrac13, an=2∫01x2cos⁡nπx dx=4(−1)nn2π2a_n = 2\int_0^1 x^2\cos n\pi x\,dx = \dfrac{4(-1)^n}{n^2\pi^2}: −4π2≈−0.405285-\tfrac4{\pi^2} \approx -0.405285, 1π2≈0.101321\tfrac1{\pi^2} \approx 0.101321.
    RatMath code
    String(analytic.fourier("x^2", [-1, 1], { terms: 2 }).exact())
    Output
    0.333333 - 0.405285*cos(pi*x) + 0.101321*cos(2*pi*x)
  4. 4.Value at a jumpAgrees
    To what does the Fourier series of the square wave converge at x=0x = 0?
    Independent answer
    To the average of the one-sided limits, −1+12=0\tfrac{-1 + 1}{2} = 0 (every sin⁡nπ⋅0=0\sin n\pi\cdot0 = 0).
    RatMath code
    analytic.fourier("-1 if -1:x:!0; 1 if 0:x:1", [-1, 1], { terms: 9 }).exact().value(0)
    Output
    -0.00000000004839537745:0.00000000004839537745
  5. 5.OrthogonalityAgrees
    Compute ∫−ππsin⁡2xsin⁡3x dx\int_{-\pi}^{\pi}\sin 2x\sin 3x\,dx and ∫−ππsin⁡22x dx\int_{-\pi}^{\pi}\sin^2 2x\,dx.
    Independent answer
    sin⁡2xsin⁡3x=12(cos⁡x−cos⁡5x)\sin2x\sin3x = \tfrac12(\cos x - \cos5x) integrates to 0. sin⁡22x=12(1−cos⁡4x)\sin^2 2x = \tfrac12(1 - \cos4x) integrates to π\pi.
    RatMath code
    [symbolic.integrate("sin(2x)*sin(3x)", "x", { from: "-pi", to: "pi" }).value, symbolic.integrate("sin(2x)^2", "x", { from: "-pi", to: "pi" }).value]
    Output
    [0, pi]
  6. 6.Parseval's identityAgrees
    Use Parseval's identity for f(x)=xf(x) = x on (−1,1)(-1, 1) to find ∑1/n2\sum 1/n^2.
    Independent answer
    ∫−11x2=23=∑bn2=∑4n2π2\int_{-1}^1 x^2 = \tfrac23 = \sum b_n^2 = \sum \dfrac{4}{n^2\pi^2}, so ∑1n2=π26\sum \dfrac1{n^2} = \dfrac{\pi^2}6.
    RatMath code
    [symbolic.integrate("x^2", "x", { from: -1, to: 1 }).value, symbolic.sum("4/(n^2*pi^2)", "n", 1, "inf").value, symbolic.sum("1/n^2", "n", 1, "inf").value]
    Output
    [2/3, 2/3, pi^2/6]
    A factor without the index, here 4/π24/\pi^2, comes outside the sum first, so both sides of Parseval's identity come out as 23\tfrac23.
    Fix: ratmath/symbolic#9, completeSquare, compose, sinusoid, inverse trig values, within, RealSet operations and chained inequalities, implicitDiff, leibniz, constant factors in sum
  7. 7.Discrete Fourier transformAgrees
    Compute the DFT Xk=∑jxje−2πijk/4X_k = \sum_j x_j e^{-2\pi ijk/4} of (1,2,3,4)(1, 2, 3, 4).
    Independent answer
    X0=10X_0 = 10, X1=1−2i−3+4i=−2+2iX_1 = 1 - 2i - 3 + 4i = -2 + 2i, X2=1−2+3−4=−2X_2 = 1 - 2 + 3 - 4 = -2, X3=−2−2iX_3 = -2 - 2i.
    RatMath code
    analytic.dft([1, 2, 3, 4]).text
    Output
    ["10", "-2 + 2ζ", "-2", "-2 - 2ζ"]
    Exact answers are written with ζ=e2πi/n\zeta = e^{2\pi i/n}; for n=4n = 4, ζ=i\zeta = i.
  8. 8.DFT of an impulseAgrees
    Find the DFT of (1,0,0,0)(1, 0, 0, 0).
    Independent answer
    Only j=0j = 0 contributes: Xk=1X_k = 1 for every kk, a flat spectrum.
    RatMath code
    analytic.dft([1, 0, 0, 0]).text
    Output
    ["1", "1", "1", "1"]
  9. 9.AliasingAgrees
    A 7 Hz sine is sampled at 10 Hz. What frequency does it appear to have?
    Independent answer
    The Nyquist frequency is 5 Hz; 77 folds to 10−7=310 - 7 = 3 Hz, and a sine comes back with its sign reversed: sin⁡(2π⋅7n/10)=−sin⁡(2π⋅3n/10)\sin(2\pi\cdot7n/10) = -\sin(2\pi\cdot3n/10).
    RatMath code
    const a = analytic.alias(7, 10);
    [a.alias, a.sign, a.aliased]
    Output
    [3, -1, true]
  10. 10.Fourier transformAgrees
    Find f^(ω)=∫−∞∞f(x)e−iωxdx\hat f(\omega) = \int_{-\infty}^\infty f(x)e^{-i\omega x}dx for f=e−∣x∣f = e^{-|x|} and for f=e−x2f = e^{-x^2}.
    Independent answer
    ∫0∞e−x(1+iω)dx+∫0∞e−x(1−iω)dx=21+ω2\int_0^\infty e^{-x(1 + i\omega)}dx + \int_0^\infty e^{-x(1 - i\omega)}dx = \dfrac{2}{1 + \omega^2}. The Gaussian: π e−ω2/4\sqrt\pi\,e^{-\omega^2/4}.
    RatMath code
    [analytic.fourierTransform("exp(-abs(x))").formula.text, analytic.fourierTransform("exp(-x^2)").formula.text]
    Output
    ["2/(w^2 + 1)", "sqrt(pi)*exp(-1/4*w^2)"]
  11. 11.ConvolutionAgrees
    Compute (f∗f)(1)(f * f)(1) for f=e−∣x∣f = e^{-|x|}.
    Independent answer
    (f∗f)(x)=(1+∣x∣)e−∣x∣(f * f)(x) = (1 + |x|)e^{-|x|} (or invert 4(1+ω2)2\dfrac{4}{(1 + \omega^2)^2}): (f∗f)(1)=2e≈0.735759(f * f)(1) = \dfrac2e \approx 0.735759.
    RatMath code
    analytic.convolution("exp(-abs(x))", "exp(-abs(x))").at(1)
    Output
    0.7357588823428846[3133:4755]
  12. 12.Laplace transformAgrees
    Find the Laplace transforms of t2t^2 and e2tsin⁡3te^{2t}\sin 3t.
    Independent answer
    L{tn}=n!sn+1\mathcal L\{t^n\} = \dfrac{n!}{s^{n+1}}: 2s3\dfrac2{s^3}. Shifting 3s2+9\dfrac3{s^2 + 9}: 3(s−2)2+9\dfrac{3}{(s - 2)^2 + 9}.
    RatMath code
    [analytic.laplace("t^2"), analytic.laplace("exp(2t)*sin(3t)")].map(String)
    Output
    ["2/s^3", "3/((s - 2)^2 + 9)"]
  13. 13.Inverse Laplace transformAgrees
    Find L−1{1s(s+1)}\mathcal L^{-1}\left\{\dfrac{1}{s(s + 1)}\right\}.
    Independent answer
    1s−1s+1\dfrac1s - \dfrac1{s + 1}, so 1−e−t1 - e^{-t}.
    RatMath code
    String(analytic.inverseLaplace("1/(s*(s+1))").result)
    Output
    1 - exp(-t)
  14. 14.Legendre polynomialsAgrees
    Find P3(x)P_3(x).
    Independent answer
    Rodrigues: P3=148d3dx3(x2−1)3=12(5x3−3x)P_3 = \tfrac1{48}\dfrac{d^3}{dx^3}(x^2 - 1)^3 = \tfrac12(5x^3 - 3x).
    RatMath code
    analytic.legendre(3)
    Output
    [0, -3/2, 0, 5/2]
    The answer is a coefficient list, constant term first.
  15. 15.Sturm–Liouville eigenvaluesAgrees
    Find the first three eigenvalues of −y′′=λy-y'' = \lambda y, y(0)=y(1)=0y(0) = y(1) = 0.
    Independent answer
    y=sin⁡nπxy = \sin n\pi x, λn=n2π2\lambda_n = n^2\pi^2: 9.86969.8696, 39.478439.4784, 88.826488.8264.
    RatMath code
    analytic.sturmLiouville({ interval: [0, 1], count: 3 }).map((e) => e.eigenvalue)
    Output
    [9869603901/1000000000:9869604901/1000000000, 2467401069/62500000:4934802263/125000000, 88826439111/1000000000:88826440111/1000000000]
    The interval needs rational ends, so the classic [0,π][0, \pi] (eigenvalues 1,4,91, 4, 9) is refused.
  16. 16.Heat equationAgrees
    Solve ut=uxxu_t = u_{xx} on 0<x<10 < x < 1 with u=0u = 0 at both ends and u(x,0)=sin⁡πxu(x, 0) = \sin\pi x. Find u(12,110)u(\tfrac12, \tfrac1{10}).
    Independent answer
    u=e−π2tsin⁡πxu = e^{-\pi^2t}\sin\pi x; u(12,110)=e−π2/10≈0.372708u(\tfrac12, \tfrac1{10}) = e^{-\pi^2/10} \approx 0.372708.
    RatMath code
    analytic.heat({ k: 1, length: 1, initial: "sin(pi*x)", terms: 3 }).at("1/2", "1/10").value
    Output
    0.37270[755611254181306:812159433401409]
  17. 17.Wave equationAgrees
    A string of length 1 with c=1c = 1 starts at rest in the shape sin⁡πx\sin\pi x. Find the displacement at x=12x = \tfrac12 at t=12t = \tfrac12 and t=13t = \tfrac13.
    Independent answer
    u=sin⁡πxcos⁡πtu = \sin\pi x\cos\pi t: u(12,12)=0u(\tfrac12, \tfrac12) = 0, u(12,13)=12u(\tfrac12, \tfrac13) = \tfrac12.
    RatMath code
    const W = analytic.wave({ length: 1, position: "sin(pi*x)" });
    [W.at("1/2", "1/2"), W.at("1/2", "1/3")]
    Output
    [-0.00000000000000000001:0.00000000000000000001, 0.[49999999999999999999:50000000000000000001]]
  18. 18.Laplace's equation on a discAgrees
    Solve Δu=0\Delta u = 0 in the unit disc with u=cos⁡θu = \cos\theta on the boundary. Find uu at r=12r = \tfrac12, θ=0\theta = 0.
    Independent answer
    u=rcos⁡θu = r\cos\theta (harmonic and right on the circle): u=12u = \tfrac12.
    RatMath code
    const u = analytic.laplaceDisc({ boundary: "cos(theta)" });
    [u.closedForm, u.at("1/2", 0).value]
    Output
    ["r*cos(theta)", 1/2]
    Boundary values with finitely many modes give the exact finite sum: the solution is rcos⁡θr\cos\theta and the value is the fraction 12\tfrac12, with no tail.
    Fix: ratmath/analytic#20, nFor, deltaFor and verifyCertificate; supremum, limsup, liminf; limits of f(n)g(n)f(n)^{g(n)}; uniform convergence decided both ways; pde.transport; exact finite-mode Laplace solutions
  19. 19.Convolution theoremAgrees
    Check the convolution theorem f∗g^=f^ g^\widehat{f * g} = \hat f\,\hat g for f=g=e−∣x∣f = g = e^{-|x|} at x=1x = 1.
    Independent answer
    f^g^=4(1+ω2)2\hat f\hat g = \dfrac{4}{(1 + \omega^2)^2}, whose inverse transform at 1 is 12π∫4eiω(1+ω2)2dω=2e−1\dfrac{1}{2\pi}\int\dfrac{4e^{i\omega}}{(1 + \omega^2)^2}d\omega = 2e^{-1}, the same as the direct convolution.
    RatMath code
    const r = analytic.convolution("exp(-abs(x))", "exp(-abs(x))").theorem(1);
    [r.agrees, r.viaTransforms]
    Output
    [true, 0.7357588[7243462884235:9227470254627]]
  20. 20.Mean-square convergenceAgrees
    For f(x)=xf(x) = x on (−1,1)(-1, 1), find the mean square error 12∫−11(f−S3)2 dx\tfrac12\int_{-1}^1 (f - S_3)^2\,dx of the 3-term Fourier sum S3S_3.
    Independent answer
    By Bessel's equality, ∫−11(f−S3)2=∫−11x2−∑n≤3bn2=23−4π2(1+14+19)=23−499π2≈0.115029\int_{-1}^1 (f - S_3)^2 = \int_{-1}^1 x^2 - \sum_{n\le3} b_n^2 = \tfrac23 - \tfrac4{\pi^2}\left(1 + \tfrac14 + \tfrac19\right) = \tfrac23 - \tfrac{49}{9\pi^2} \approx 0.115029. Half of that is ≈0.0575146\approx 0.0575146.
    RatMath code
    analytic.fourier("x", [-1, 1], { terms: 3 }).exact().meanSquareError()
    Output
    0.05751455563627443977:0.0575145556456395458