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 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