clear; clf(); lambda=10; %Wavelength k=2*pi/lambda; %Wave number x=0:0.01:40; %plot range c0 = 1/2;%Y axis offset f_x= c0/2; c = 2/pi*[1, 0, -1/3, 0, 1/5, 0, -1/7]; % c is a vector representing the coefficients max = numel(c); %determines the number of coefficients we have in the vector for i=1:max f = cos(i*k*x); %creates a vector of cos(ikx) f_x = f_x + c(i)*f; %this makes the total f vector end %can also build using a matrix method in the for loop: %fmat(i,:) = f; %creates a matrix storing all vectors %then use: %f_x= c0/2 + c(1)*fmat(1,:) + c(2)*fmat(2,:) + c(3)*fmat(3,:) + c(4)*fmat(4,:); plot(x, f_x);