SawToothFourier
<source lang="text"> % % _-_,, ,, _-_- ,, % ( // || /, _ ; || ' % _|| /'\\ ||/\\ \\/\\ || __ < \, \\/\/\ ||/\ \\ \\/\\ _-_, % _|| || || || || || || ~||- - /-|| || | | ||_< || || || ||_. % || || || || || || || ||===|| (( || || | | || | || || || ~ || % -__-, \\,/ \\ |/ \\ \\ ( \_, | \/\\ \\/\\/ \\,\ \\ \\ \\ ,-_- % _/ ` % % John Hawkins % LNA % Sawtooth Wave Fourier Example % 12 Jan 2010
t=linspace(-1,1,1000);
x=t-floor(t);
figure
plot(t,x,'k')
hold on;
f=1/2*ones(1,numel(t));
for n=1:100
temp=-1/(pi*n)*sin(2*n*pi*t);
f=f+temp;
plot(t,temp+1/2);
switch n
case 1
f1=f;
case 3
f3=f;
case 5
f5=f;
case 10
f10=f;
case 50
f50=f;
end
end
plot(t,f,'r');
axis equal;
fontsize=20;
title({['Sawtooth Wave Constructed of First 100 Terms'],...
['of Fourier Series, Each Term Shown']},...
'fontname','times','fontsize',fontsize)
xlabel('t'); ylabel('x');
figure
plot(t,f1,t,f3,t,f5,t,f10,t,f50,t,f)
axis equal
title('Sawtooth Wave Constructed of First n Terms',...
'fontname','times','fontsize',fontsize);
xlabel('t'); ylabel('x');
legend('n=1','3','5','10','50','100','location','northwest');
</source>