Borrar filtros
Borrar filtros

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

3 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

Walter Roberson
Walter Roberson el 4 de Mzo. de 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

Más respuestas (0)

Categorías

Más información sobre Spline Postprocessing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by