How can I plot this Fourier series in a for loop?
조회 수: 12 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (1개)
Alexander
2023년 11월 22일
t is not defined.
댓글 수: 2
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 Center 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!