Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Create a MATLAB function in its own script file called FourierSeries.m. This

ID: 2265667 • Letter: 1

Question

1. Create a MATLAB function in its own script file called FourierSeries.m. This function should take in an anonymous function f and the desired degree n. So the first line of this function file should look like this: function FS = FourierSeries(f,n)

2. Create a new function in a script file called Proj2Func1.m which contains the following code: function f = Proj2Func1(x): f = x.ˆ2;

3. In a file called Proj2Func2.m create the following function: f(x) = (piecewise) 5 if x < 2; 0 if 2 x < 1; 1 if x >= 1

4. In a file called Proj2Func3.m create the function which starts at (, 0) and goes linearly up to (1, 1), linearly down to (2, 4), and then linearly up to (, 3).

5. Create variables called FS1, FS2, and FS3 which are the fourth degree Fourier series of the three functions. Remember they will be anonymous functions because that’s what the Fourier series file returns.

6. Plot FS1 and Proj2Func1 on the same graph with the x-axis going from to . Describe how well the Fourier series approximates this function. Is the approximation close at all points or just some points?

7. Plot FS2 and Proj2Func2 on the same graph with the x-axis going from to . Describe how well the Fourier series approximates this function. Is the approximation close at all points or just some points?

8. Plot FS3 and Proj2Func3 on the same graph with the x-axis going from to . Describe how well the Fourier series approximates this function. Is the approximation close at all points or just some points?

9. Finally, repeat everything you’ve done so far, but using the 8th degree Fourier series of the functions instead of the 4th degree.

Explanation / Answer

1.According to chegg policy i have to answer only 1st question:

So the matlab function of 1st part is as follows:

function FS = FourierSeries(f,n)
syms t % variable t
pi=3.14; % constant pi
sum=0; %initiate sum=0

for m=1:n
g=@(t) cos(m*t).*f(t);
h=@(t) sin(m*t).*f(t);
a0=(1/pi)*integral(f,-pi,pi) ; %coefficients a0
an=(1/pi)*integral(g,-pi,pi); %finding coefficient an
bn=(1/pi)*integral(h,-pi,pi) ; % finding coefficient bn
sum=sum+(an*cos(m*t)+bn*sin(m*t)); % updating sum value
end
fplot(t,f,[-pi,pi]);
grid on;
hold on;
fplot(t,(sum+a0/2),[-pi,pi]);