MATLAB: How to sum a series of functions and then plot the sum

plottingsymsum

This function is supposed to be able to plot a box filter:
That should possibly look like this:
I already defined t as a 1×360 double array using:
t = t = linspace(0, 4, 360)
syms k
z = symsum( (1 / k) * sin((2 * pi) * k * t ), k, 1, 10) ;
It returns a 1×360 sym variable, but I don't know how to plot it.

Best Answer

clear variables
close all
M = 250; % The length of each function
A=3;
t = -2:4/(M-1):2;
y = zeros(1,M); % Initiallize the sum to zero
N = 100;
for k = 1:N
ck = 1/k;
y = y+ A*ck*sin(pi*k*t); % computing the sum
end
plot(t,y,'linewidth',2,'color','m')
a= title('y(t) : sum of sine wave');
set(a,'fontsize',14);
a= xlabel('x [-2\pi 2\pi]');
set(a,'fontsize',20);
a = ylabel('y');
set(a,'fontsize',20);
a = zlabel('z');
set(a,'fontsize',20);
grid;
Related Question