Fourier series plot as sums of sines and cosines

4 ビュー (過去 30 日間)
Antonello Carloni
Antonello Carloni 2021 年 11 月 3 日
編集済み: Sulaymon Eshkabilov 2021 年 11 月 3 日
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
Sulaymon Eshkabilov 2021 年 11 月 3 日
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 件のコメント
Antonello Carloni
Antonello Carloni 2021 年 11 月 3 日
Thank you! 7 blessings!
Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021 年 11 月 3 日
編集済み: Sulaymon Eshkabilov 2021 年 11 月 3 日
Most welcome!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Exploration についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by