clc
clear

x=linspace(-pi,pi,1000);
f=zeros(size(x));
f(x>0 & x<pi)=1;
f(x>-pi& x<0)=-1;
f_fourier = (4/pi) * (sin(x)/1 + sin(3*x)/3 + sin(5*x)/5 + sin(7*x)/7);
plot(x, f, 'b-'); hold on;
plot(x, f_fourier, 'r-');
title('Fourier Series Functions by courtni k.');
xlabel('x');
ylabel('Functions');

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: