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!