function [ft] = fwave(N,t) % Fourier Expansion of abs(x) on (0,2*pi) % Output: function ft = Nth partial sum of Fourier Series % Input: N = Number of terms to take in summation K = 1.0; % Define interval of interest: x = [0:0.01:6]; % Zero output function: ft = zeros(1,length(x)); %Set a0 term: ft = 0; % Compute each 'a' and 'b' and sum: for n = 1:N a = 0; b = 2*(cos(n*pi/3)-cos(2*n*pi/3))/(pi*n); b = b*cos(K*n*pi*t/6); ft = ft + a*cos(n*x) + b*sin(n*pi*x/6); end % All Done! return