function [ft] = fheat(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 = 0.1; % Define interval of interest: x = [0:0.005:pi]; % 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 = 20*(1-(-1)^n)/(n*pi); b = 40/((2*n-1)*pi); b = b*exp(-K*(2*n-1)^2*t); ft = ft + a*cos(n*x) + b*sin((2*n-1)*x); end % All Done! return