Fourier sine series plotting first term, first five term, and first 15 terms on one graph
2 views (last 30 days)
Show older comments
Katie Beeler
on 4 Mar 2024
Commented: Katie Beeler
on 4 Mar 2024
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.
0 Comments
Accepted Answer
Walter Roberson
on 4 Mar 2024
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
More Answers (0)
See Also
Categories
Find more on Spline Postprocessing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!