Fourier series plot as sums of sines and cosines

4 Ansichten (letzte 30 Tage)
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!

Akzeptierte Antwort

Sulaymon Eshkabilov
Sulaymon Eshkabilov am 3 Nov. 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')

Weitere Antworten (0)

Kategorien

Mehr zu Data Exploration finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by