1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 % plot for Trig Fourier Series of f(x)=x. % (after JBR solution) %MDG 11/25/12 nxs = 301; % number of points x = linspace(-pi, pi, nxs); %points for plotting nterms = [5, 10, 50]; % number of terms for sums u = zeros(length(nterms), nxs); for i = 1:length(nterms) for k = 1:nterms(i); sign = (-1)^k; un0 = -2*sign/k; u(i,:) = u(i,:)+ un0*sin(k*(x)); end end plot(x,u) table = [x' u']; save Fourierx.dat table