Chapter 1 - Explorations

173 days ago by MichaelDeveau

Chapter 1 - Explorations

1.1.3 - Approximating Fourier's Solution

reset(); var('x,w'); def z(x,w,a): var('k'); s = 0; for k in [1..len(a)]: s += a[k-1]*exp((1/2*(2*k-1)*(-pi)*w))*(cos(1/2*(2*k-1)*pi*x)); return s; 
       

a is the list of coefficients. The length of a determines the number of terms in the series.

a = [1, -1/2, 1/3, -1/4, 1/5]; z(x,w,a) 
       
1/5*e^(-9/2*pi*w)*cos(9/2*pi*x) - 1/4*e^(-7/2*pi*w)*cos(7/2*pi*x) +
1/3*e^(-5/2*pi*w)*cos(5/2*pi*x) - 1/2*e^(-3/2*pi*w)*cos(3/2*pi*x) +
e^(-1/2*pi*w)*cos(1/2*pi*x)
1/5*e^(-9/2*pi*w)*cos(9/2*pi*x) - 1/4*e^(-7/2*pi*w)*cos(7/2*pi*x) + 1/3*e^(-5/2*pi*w)*cos(5/2*pi*x) - 1/2*e^(-3/2*pi*w)*cos(3/2*pi*x) + e^(-1/2*pi*w)*cos(1/2*pi*x)

The first command produces a 3-dimensional plot of z(x,w), the second produces the cross-section parallel to the w-axis at x=0, and the third produces the cross-section above the x-axis.

plot3d(lambda x,w: z(x,w,a), (x,-1,1), (w,0,2)).show(); plot(lambda w: z(0,w,a), (w,0,2)).show(); plot(lambda x: z(x,0,a), (x,-1,1)).show(); 
       


This function is the first n terms of Fourier's approximation to the constant function 1.

def FS(n,x): return 4/pi*sum((-1)^(k-1)/(2*k-1)*cos(1/2*(2*k-1)*pi*x), k, 1, n); 
       

Plot Fourier's approximation with 6 terms.

plot(lambda x: FS(6,x), (x,-1,1)).show(); 
       

This function is the first n terms approximation of the solution to the heat equation with the boundary function as the constant function 1.

def FSS(n,x,w): return 4/pi*sum((-1)^(k-1)/(2*k-1)*exp(1/2*(-2*k+1)*pi*w)*cos(1/2*(2*k-1)*pi*x), k, 1, n); 
       

Plot the 6-term solution to the heat equation.

plot3d(lambda x,w: FSS(6,x,w), (x,-1,1), (w,0,2)).show();