Fourier sine series plotting first term, first five term, and first 15 terms on one graph
3 次查看(过去 30 天)
显示 更早的评论
I need help plotting only the first terms of my fourier sine series, then the first five terms, and the first fifteen terms on one graph. This is my code thus far:
x = 0:0.1:25;
n = 10;
ysin = fsin(x,n);
plot(x,ysin),grid
xlabel('x'),ylabel('sin function')
% Define functions
function f = fsin(x,n)
f = zeros(1,numel(x));
f = 2;
for i = 1:n
an = -4*(cos(i*pi/2)-1)/(i*pi);
f = f + an*sin(i*pi*x/50);
end
end
For reference my series is
. I made L = 50 and my sum is running from n=1 to infinity.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1634021/image.png)
0 个评论
采纳的回答
Walter Roberson
2024-3-4
x = 0:0.1:25;
n = 1;
ysin = fsin(x,n);
plot(x,ysin)
hold on
n = 5;
ysin = fsin(x,n);
plot(x,ysin)
hold on
n = 15;
ysin = fsin(x,n);
plot(x,ysin)
hold on
grid on
xlabel('x')
ylabel('sin function')
hold off
% Define functions
function f = fsin(x,n)
f = zeros(1,numel(x));
f = 2;
for i = 1:n
an = -4*(cos(i*pi/2)-1)/(i*pi);
f = f + an*sin(i*pi*x/50);
end
end
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spline Postprocessing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!