Problem 1
Find the Fourier Cosine series for the function, on the interval and .
First, clear the workspace and define .
> restart: f := x -> x*(Pi - x);
Next, compute .
> a[0] := (2/(2*Pi))*int(f(x),x=0..Pi);
Then compute the general coefficient, .
> a[k] := (2/Pi)*int(f(x)*cos(k*x),x=0..Pi);
Note that if is an integer, then the term involving will be zero. Also, .
To use this coefficient expression in the series, we need to make it a function of .
> coef := unapply(a[k],k);
It is easy to see the pattern for the coefficients.
> a[1] := coef(1);a[2] := coef(2);a[3] := coef(3);a[4] := coef(4);a[5] := coef(5);a[6] := coef(6);
The series - actually an arbitrary partial sum of the series - can be simply defined by
> CF := (x,N) -> a[0]+sum(coef(k)*cos(k*x),k=1..N);
We can verify the convergence of the series by looking a the first few approximations.
> plot([f(x),CF(x,0),CF(x,2),CF(x,4),CF(x,6)],x=0..Pi);
A more informative plot for higher order approximations is a plot of the error.
> plot((f(x)-CF(x,50)),x=0..Pi);