Filter löschen
Filter löschen

Fourier sine series plotting first term, first five term, and first 15 terms on one graph

3 Ansichten (letzte 30 Tage)
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.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 4 Mär. 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

Weitere Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by