我有这个和Σ((4./pi)*((( - 1)。^ n)/(2 * n + 1))* cos((2 * n + 1)* x)) x = 0到4 * pi和n = 0到24.我想用for循环来计算它的总和。
这是我的代码:
x=4*pi % it does not work when I put x=0:4*pi , matlab says : In an assignment A(I) = B, the number of elements in B and I must be the same.
for n=0:length(x)
f(i+1)= (4./pi).*(((-1).^n)./(2*n+1))*cos((2*n+1)*x);
end
xl=sum(f);
如何修复x从0变为4 * pi?
由于
编辑:
x=0:4*pi;
for n=0:13
f(i+1)= (4./pi).*(((-1).^n)./(2*n+1))*cos((2*n+1)*x(n));
end
xl=sum(f);