# i need the curve of this fourier series

1 vue (au cours des 30 derniers jours)
bob le 9 Août 2022
Commenté : John D'Errico le 1 Oct 2022
can you help me to plot this saw-tooth graph on matlab?
a0 = π
an = 2/n sin(n*π)
bn = -2/n cos(n*π)
this is the full question :
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponses (1)

Karim le 9 Août 2022
see below for a demo on how to set this up
% set up the x values
x = linspace(-3*pi, 3*pi, 1e3);
% assume 10 terms for the first curve
n = 10;
% initialize with pi
f_10 = pi;
for ni = 1:n
if mod(ni,2) == 0
% add contribution for the even ni
f_10 = f_10 - 2 * (1/ni).*sin(ni.*x);
else
% add contribution for the odd ni
f_10 = f_10 + 2 * (1/ni).*sin(ni.*x);
end
end
% do the same for 100 terms...
n = 25;
f_25 = pi;
for ni = 1:n
if mod(ni,2) == 0 % even term
f_25 = f_25 - 2 * (1/ni).*sin(ni.*x);
else
f_25 = f_25 + 2 * (1/ni).*sin(ni.*x);
end
end
% plot both
figure
plot(x,[f_10;f_25])
grid on
legend("n = 10","n = 25")
##### 1 commentaireAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens
John D'Errico le 1 Oct 2022
Please don't do obvious homework assignments for people that have made no effort of their own.

Connectez-vous pour commenter.

### Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

R2018a

### Community Treasure Hunt

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

Start Hunting!

Translated by