フィルターのクリア

Fourier sine series plotting first term, first five term, and first 15 terms on one graph

3 ビュー (過去 30 日間)
I need help plotting only the first terms of my fourier sine series, then the first five terms, and the first fifteen terms on one graph. This is my code thus far:
x = 0:0.1:25;
n = 10;
ysin = fsin(x,n);
plot(x,ysin),grid
xlabel('x'),ylabel('sin function')
% Define functions
function f = fsin(x,n)
f = zeros(1,numel(x));
f = 2;
for i = 1:n
an = -4*(cos(i*pi/2)-1)/(i*pi);
f = f + an*sin(i*pi*x/50);
end
end
For reference my series is . I made L = 50 and my sum is running from n=1 to infinity.

採用された回答

Walter Roberson
Walter Roberson 2024 年 3 月 4 日
x = 0:0.1:25;
n = 1;
ysin = fsin(x,n);
plot(x,ysin)
hold on
n = 5;
ysin = fsin(x,n);
plot(x,ysin)
hold on
n = 15;
ysin = fsin(x,n);
plot(x,ysin)
hold on
grid on
xlabel('x')
ylabel('sin function')
hold off
% Define functions
function f = fsin(x,n)
f = zeros(1,numel(x));
f = 2;
for i = 1:n
an = -4*(cos(i*pi/2)-1)/(i*pi);
f = f + an*sin(i*pi*x/50);
end
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpline Postprocessing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by