Hi alexmahone!
Perhaps you should write
y=y+4*sin(k*x)/(pi*k);
instead of:
y=y+4*sin(k*x)/pi*k;
Suppose is a square wave of period such that
for
for
The Fourier series for is
I tried plotting this using MATLAB (using the first 10 terms):
I have attached my output but it doesn't look anything like a square wave. What am I doing wrong?Code:x=linspace(-4*pi,4*pi,100); y=0; k=1; for n=1:10 y=y+4*sin(k*x)/pi*k; k=k+2; end plot(x,y) axis([-4*pi 4*pi -2 2]) xlabel('x') ylabel('Square wave approximation using first 10 terms')