i hav created these fourier series but want to plot each iteration in one plot but i do not know how?any help?
dx = 0.001
L = 2
x = seq(0,L+dx,dx)
n = length(x);n
y = floor(n/4);y
f = rep(0,length(x));f
a = 0
b = y;b
c = y*2;c
d = y*3;d
e = n;e
f[a:b] = 0
f[b:c] = 1
f[c:d] = 1
f[d:e] = 0
f
A0 = sum(f * rep(1,n)) *dx
fFS = (A0/2)
n = 1000
Am = numeric(n)
Bm = numeric(n)
for(i in 1:n){
Am[i] = sum(f * cos((2*pi*(i)*x)/L)) * dx
Bm[i] = sum(f * sin((2*pi*(i)*x)/L)) * dx
fFS = fFS + Am[i]*cos((2*(i)*pi*x)/L) + Bm[i]*sin((2*(i)*pi*x)/L)
plot(x,fFS,type="l","col"=i+1)
}