How do I plot every nth vector of this Fourier series?

조회 수: 1 (최근 30일)
Kristinn Arnar Ormsson
Kristinn Arnar Ormsson 2016년 9월 17일
댓글: Kristinn Arnar Ormsson 2016년 9월 17일
I would like to plot every nth outcome (f) of this Fourier series function but don't know how to do it. Can anyone help me and show me how that can be done?
t = 0:.02:2*pi; % Graph time, interval between 0 and 2pi
f = 0*t; % Make function variable same as time
for n = 1:1:1000;
if mod(n,2)==1 % only use when n is a odd number
b_n = ((4)/(n*pi)) % calc of bn
f_n = b_n*sin(n*t) % calc of bn times summotation
f = f + f_n; % add to last
end
end
plot(t,f,'-');
grid on;
xlabel('t');
ylabel('f(t)');
title(strcat('The building of a square wave: Gibbs'' effect'));

답변 (1개)

Mischa Kim
Mischa Kim 2016년 9월 17일
편집: Mischa Kim 2016년 9월 17일
Hi Kristinn, do you mean something like this:
t = 0:.02:2*pi; % Graph time, interval between 0 and 2pi
f = 0*t; % Make function variable same as time
hold on
plot_n = 5;
for n = 1:1:1000
if mod(n,2)==1 % only use when n is a odd number
b_n = ((4)/(n*pi)); % calc of bn
f_n = b_n*sin(n*t); % calc of bn times summotation
f = f + f_n; % add to last
end
if ~mod(n,plot_n)
plot(t,f)
end
end
grid on;
xlabel('t');
ylabel('f(t)');
title(strcat('The building of a square wave: Gibbs'' effect'));
  댓글 수: 5
Mischa Kim
Mischa Kim 2016년 9월 17일
Absolutely correct. In the code above every 5th line is plotted.
Kristinn Arnar Ormsson
Kristinn Arnar Ormsson 2016년 9월 17일
Perfect, thank you for taking the time to help me!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by