Fourier series plot as sums of sines and cosines

3 visualizaciones (últimos 30 días)
Hi there,
founding troubles in plotting a simple Fourier series.
f(x)=16pi^4\5+16Σ((2pi^2\n^2)-(3\n^4))cos(nx)+16piΣ(3\n^3)-(pi^2\4n))sin(nx)
from 0 to 5
then from 0 to 10 and then compare with the real cosx function,
I know, I am J.... but I cannot figure it out. I tried with the examples posted but nothing seems to be working.
Can any good samaritan help me figuring this out? Thank U all!

Respuesta aceptada

Sulaymon Eshkabilov
Sulaymon Eshkabilov el 3 de Nov. de 2021
This can be done in a few different ways, such as vectorization, [for .. end] and [while .. end] loops. E.g.:
clc; clearvars; close all;
x = linspace(0, 2*pi, 500);
S = 16*pi*4/5;
n = 1:5;
S1 = 16*((2*pi^2./n(:).^2)-(3/n(:).^4))*cos(n(:).*x);
S2 = 16*pi*((3./n(:).^3)-((pi^2)./n(:).^3)).*sin(n(:).*x);
SS_n5 = S+sum(S1)+sum(S2);
subplot(211)
plot(x, SS_n5, 'r-'); title('n = 1:5')
n = 1:10;
S1 = 16*((2*pi^2./n(:).^2)-(3/n(:).^4))*cos(n(:).*x);
S2 = 16*pi*((3./n(:).^3)-((pi^2)./n(:).^3)).*sin(n(:).*x);
SS_n10 = S+sum(S1)+sum(S2);
subplot(212)
plot(x, SS_n10, 'b-')
title('n = 1:10')
figure()
plot(x, SS_n5, 'r', 'DisplayName', 'n=1:5'), hold on
plot(x, SS_n10, 'b', 'DisplayName', 'n=1:10')
legend, grid on; shg
title('Fourier Series')
  2 comentarios
Antonello Carloni
Antonello Carloni el 3 de Nov. de 2021
Thank you! 7 blessings!
Sulaymon Eshkabilov
Sulaymon Eshkabilov el 3 de Nov. de 2021
Editada: Sulaymon Eshkabilov el 3 de Nov. de 2021
Most welcome!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Exploration en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by