#import "@preview/physica:0.9.6": * #import "lib.typ": ccases = problem 2 == a) click the code to obtain the sketches for the expansions of $f(x)$. #link( "https://uiua.org/pad?src=0_18_0-dev_2__eJxTVnCtKEgtysxNzStJzFHkqlNQSs8ssVJIzyzJKE3SS87P1ffPzcvMTizSL80sTdQtyMkvUVKoU3BJLElUCMjJL-F61LHyUc_8R11Nj7p2HFr_qL3nUdeOR20zDBUeNU08vP3R_DmP2hcamkKUzXvUNV_X8PB0o8PbdQ1B6pbvPrThUVc_SFYDZBrE3Ee9nZpcAB-1SDo=", )[```uiua # Experimental! ~ "git: github.com/Omnikar/uiua-plot" ~ Data Plot ∩⌟⊂⊸¯⇌⊸↘1 ₑ÷⟜⇡15 ∩⌞⊟-1×2÷-1⊸⧻°⊏ ∩(Plot Data ⍉) ```] #image("./2a_even_expansion.png") this is how the even expansion would look. #image("./2a_odd_expansion.png") this is how the odd expansion would look. it is a little off because i didn't bother to make a duplicate point at -1 to highlight the discrete jump. these are both created by evaluating $f(x) = exp(x)$ on $[0, 1]$, then taking those values in reverse from 0 to -1, one of them negated to obtain the odd property. == b) it makes sense that the even expansion is more practical in this case, since it is smoother and doesn't contain a discrete jump, only a point at which it isn't differentiable, but it is continuous. the gibbs artifacts will be smaller compared to the odd expansion, which will have large artifacts at the discrete jump, making for a less accurate approximation of $f(x)$ using a truncated fourier series. == c) let now $f(x) = x - x^2$ on $[0, 1]$. we only need to change our single function in the code, namely change from `ₑ` to `(-⊸°√)`. #link( "https://uiua.org/pad?src=0_18_0-dev_2__eJxTVnCtKEgtysxNzStJzFHkqlNQSs8ssVJIzyzJKE3SS87P1ffPzcvMTizSL80sTdQtyMkvUVKoU3BJLElUCMjJL-F61LHyUc_8R11Nj7p2HFr_qL3nUdeOR20zDBU0dEEiGx51zNI8vP3R_DmP2hcamkKUz3vUNV_X8PB0o8PbdQ1B6pfvPrThUVc_SFYDZCrE_Ee9nZpcAGxZTF0=", )[```uiua ... ∩⌟⊂⊸¯⇌⊸↘1 (-⊸°√)÷⟜⇡15 ... ```] #image("./2c_even_expansion.png") #table( image("./marine.png"), align(horizon)[this is how the even expansion looks.], stroke: none, columns: 2, ) #image("./2c_odd_expansion.png") this is the odd expansion. very nice. we can see that the odd expansion already resembles a sine-wave. we can then guess that this will the more accurate one of the two. == d) denote the even and odd expansions as functions respectively $ g(x) = ccases(x - x^2, x >= 0, -x - x^2)space, quad h(x) = ccases(x - x^2, x >= 0, -x + x^2) $ we can find the coefficients for these by calculating the integrals from the definitions of the coefficients $ a_0 (g) & = integral_(-1)^1 g(x) dd(x) \ & = integral_(-1)^0 (-x - x^2) dd(x) + integral_0^1 (x - x^2) dd(x) \ & = -1/2 [x^2]_(-1)^0 - 1/3 [x^3]_(-1)^0 + 1/2 [x^2]_0^1 - 1/3 [x^3]_0^1 \ & = -1/2 - 1/3 + 1/2 - 1/3 = -2/3 $ $ a_n (g) & = integral_(-1)^1 g(x) cos(2 pi n x) dd(x) \ & = integral_(-1)^0 (-x - x^2) cos(2 pi n x) dd(x) + integral_0^1 (x - x^2) cos(2 pi n x) dd(x) \ & = 2 integral_0^1 (x - x^2) cos(2 pi n x) dd(x) \ & = 2 [(x-x^2)/(2 pi n) sin(2 pi n x) + (1 - 2x)/(4 pi^2 n^2) cos(2 pi n x) + 2/(8 pi^3 n^3) sin(2 pi n x)]_0^1 \ & = 2 [-1/(4 pi^2 n^2) - 1/(4 pi^2 n^2)] \ & = -1/(pi^2 n^2) $ $ b_n (g) & = integral_(-1)^1 g(x) sin(2 pi n x) dd(x) = 0 $ $ a_0 (h) & = integral_(-1)^1 h(x) dd(x) \ & = integral_(-1)^0 (-x + x^2) dd(x) + integral_0^1 (x - x^2) dd(x) \ & = -1/2 [x^2]_(-1)^0 + 1/3 [x^3]_(-1)^0 + 1/2 [x^2]_0^1 - 1/3 [x^3]_0^1 \ & = -1/2 + 1/3 + 1/2 - 1/3 = 0 $ $ a_n (h) & = integral_(-1)^1 h(x) cos(2 pi n x) dd(x) = 0 $ $ b_n (h) & = integral_(-1)^1 h(x) sin(2 pi n x) dd(x) \ & = integral_(-1)^0 (-x + x^2) sin(2 pi n x) dd(x) + integral_0^1 (x - x^2) sin(2 pi n x) dd(x) \ & = 2 integral_0^1 (x - x^2) sin(2 pi n x) dd(x) \ & = 2 [(x^2 - x)/(2 pi n) cos(2 pi n x) + (1 - 2x)/(4 pi^2 n^2) sin(2 pi n x) -2/(8 pi^3 n^3) cos(2 pi n x)]_0^1 \ & = 0 $ well, that's definitely wrong.