function wave_packet_cosines % Figure 4.12 hold off clc dk=input('Insert dk = 0.5 = '); nmax=input('Insert the number of terms nmax = 100 = '); k1 = input('Insert initial k_0 = 100 = '); x=[-5:.001:5]; nx=length(x); % To plot the graph on [-1,1], change the interval and % the x-axis definitions below %x=[-1:.001:1]; nx=length(x); kn=[k1:dk:k1+nmax*dk]; s=0; for i=1:nmax s=s+cos(kn(i)*x*pi)/nmax; end plot(x,s,'-k','linewidth',1.2) ylabel('$f(x)$','Interpreter','latex','fontsize',36) xlabel('$x$','Interpreter','latex','fontsize',36) axis([-5 5 -1 1]) %axis([-1 1 -1 1]) set(gca,'FontSize',36) set(gca,'Ytick',[-1:.50:1],'linewidth',1.6) set(gca,'Xtick',[-5:1:5],'linewidth',1.6) %set(gca,'Xtick',[-1:.5:1],'linewidth',1.6) set(gcf, 'Units','centimeters','Papersize',[36,36]) set(gcf, 'Units','centimeters','Position',[3 3 24 20]) % Try the corresponding sine series and change parameters