Fourier series plot as sums of sines and cosines

4 次查看(过去 30 天)
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!

采纳的回答

Sulaymon Eshkabilov
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')

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Exploration 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by