Question

Please answer "b" only.

3.Consider the function { if Tt0 sint if 0t < T 0 and g(t2T) g(t) g(t) (a) Is this function continuous over the interval -r,7

%Example code
function plotFS(m);
%m = user provided number of terms desired in the Fourier series;
%this code computes the Fourier series of the function 
%f(x)=0,        for -pi<= x <0, 
%    =cos(x)    for   0<= x <pi


%generate the interval from -pi to pi with step size h;
h = pi/100;
xx1=[-pi:h:0]; 
xx2=[0:h:pi];
xx = [xx1, xx2];
%generate the given function f so that it can be graphed
ff = [zeros(size(xx1)), cos(xx2)];

%compute the first partial sum
%note this is the first column of a larger matrix used to store each
%subsequent partial sum
ps(1,:) = .5*cos(xx); % 

%compute the next partial sum using Matlab's symbolic integrator
syms x %declare the symbolic variable, used in the int command below
ps(2,:) = ps(1,:) + sin(2*xx)*int(cos(x)*sin(2*x), 0, pi)/pi;

%note that many of the coef are zero so are not included nor computed
for n = 4:2:m
    temp = int(cos(x)*sin(n*x), 0, pi)/pi;%integrate this directly
    ps(n,:) = ps(n-2,:) + temp*sin(n*xx);
    %plot(xx,ps(n,:),'k-'); hold on; %plot intermediate partial sums as
    %they're generated
end

figure(1);
%plot the original given function, over three period
plot(xx,ff,'k-', xx+2*pi*ones(size(xx)),ff,'k-',xx-2*pi*ones(size(xx)),ff,'k-'); 
hold on;
%plot the m-th partial sum
plot(xx,ps(m,:),'b-'); 
%extend the graph over two more periods
plot(xx,ps(m,:),'b-', xx+2*pi*ones(size(xx)),ps(m,:),'b-', xx-2*pi*ones(size(xx)),ps(m,:),'b-'); 
legend('Original Fc', 'm-th Partial Sum');
title('Function and its Fourier series');

return
%anything written after "return" will not be executed...
0 0
Add a comment Improve this question Transcribed image text
Answer #1


Matlab code for Fourier Series clear all close all All time values t-linspace-pi,pi,1001); creating the function op -1 : 1 if용음몸을몸을 몸을몸용 응을몸을 몸을을 po Jo pu 동용용용용을을을 동물물을동을을동동용 Yes this function is continuous and differentiable Printing few terms for F

%Matlab code for Fourier Series
clear all
close all
%All time values
t=linspace(-pi,pi,1001);
%Loop for creating the function
for i=1:length(t)
    if t(i)>=-pi && t(i)<0
        zz(i)=0;
    else
        zz(i)=sin(t(i));
    end
end
figure(1)
%Plotting the function
plot(t,zz,'Linewidth',2)
xlabel('t')
ylabel('f(t)')
title('Plotting of Actual data and Fourier sum')
a1=t(1); b1=t(end);
l=(b1-a1)/2;
%Fourier series of the function for finding a and b coefficients
for j=1:200
    ss1=zz.*cos(j*pi*t/l);
    %all a values of the Fourier series
    aa(j)=(1/l)*trapz(t,ss1);
    ss2=zz.*sin(j*pi*t/l);
    %all b values of the Fourier series
    bb(j)=(1/l)*trapz(t,ss2);
end

%a0 value of Fourier series
aa0=(1/l)*trapz(t,zz);
t=linspace(-pi,pi,6001);
s=aa0/2;
fprintf('Yes this function is continuous and differentiable.\n\n')
%all an and bn terms
fprintf('Printing few terms for Fourier series\n')
for i=1:10
    fprintf('\tThe value of a%d=%f and b%d=%f. \n\n',i,aa(i),i,bb(i))
end
lgnd{1}='Actual plot';
%Fourier series of the function
hold on
for i=1:10
  
    s=s+bb(i)*sin(i*pi*t/l)+aa(i)*cos(i*pi*t/l);
    plot(t,s)
    lgnd{i+1}=sprintf('Fourier sum for %d terms',i);  
end
legend(lgnd,'Location','northwest')

%%%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%%%
   

Add a comment
Know the answer?
Add Answer to:
Please answer "b" only. %Example code function plotFS(m); %m = user provided number of terms desired in the Fou...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT