How can I plot this Fourier series in a for loop?

조회 수: 12 (최근 30일)
Allie Ludovice
Allie Ludovice 2023년 11월 22일
댓글: Alexander 2023년 11월 22일
I am trying to plot the sine from of a fourier series using the pre-determined equations/ values for A0, Ak, and Bk. I cannot figure out how to plot the fourier series. I keep getting errors where I noted "ERROR POINT" saying "Unrecognized function or variable 't'." I'm not sure why or how to fix it, as everything I have tried, including plotting outside of the for loop and implementing another for loop for the t/ time variable, results in nothing being plotted. Any help would be much appreciated!!
A0 = 1.4;
x = A0/2; %initializing value of x for k = 0
for k=1:100
Ak = (1/(k*pi))*sin(7*k*pi/5); %hand calculated equation
Bk = -(1/(k*pi))*(cos(7*k*pi/5)-1); %hand calculated equation
Mk = sqrt(Ak^2+Bk^2);
psi_k = atan(Ak/Bk);
x = x + Mk*sin(k*t*pi/5 + psi_k); %ERROR POINT, sine form of fourier series
plot(t,x);
end

답변 (1개)

Alexander
Alexander 2023년 11월 22일
t is not defined.
  댓글 수: 2
Allie Ludovice
Allie Ludovice 2023년 11월 22일
How do I define it so it isn't just a constant? I need t to be the variable on the x axis of the plot.
Alexander
Alexander 2023년 11월 22일
I don't know if the computation makes sense but it runs w/o error:
A0 = 1.4;
xs = A0/2; %initializing value of x for k = 0
t = 1:100;
for k=1:100
Ak = (1/(k*pi))*sin(7*k*pi/5); %hand calculated equation
Bk = -(1/(k*pi))*(cos(7*k*pi/5)-1); %hand calculated equation
Mk = sqrt(Ak^2+Bk^2);
psi_k = atan(Ak/Bk);
x(k) = xs + Mk*sin(k*t(k)*pi/5 + psi_k); %former ERROR POINT, sine form of fourier series
xs = x(k);
end
plot(t,x)
Hopefully it helps.

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

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by