フィルターのクリア

Summation of a series without for loop

1 回表示 (過去 30 日間)
John
John 2014 年 12 月 28 日
コメント済み: Iyad Khuder 2020 年 11 月 12 日
Fourier series of a square wave can be represented as:
F(t)=(4/pi)*sum(1/(2k+1)*sin((2k+1)pi*t/T)
Where, sum is over k=0 to inf, T is period = 1. I need to plot F(t) for first 10 terms in the series. I can do this using loops, but is there any way to do this without any loop?

採用された回答

Shoaibur Rahman
Shoaibur Rahman 2014 年 12 月 28 日
Yes you can do this! Use vectorization technique. Try to understand the line F = ... in the following code. If you get any hard time with this, please let me know. This is a great question though.
T = 1; t = -3:0.01:3; % change time vector as what you need
n = 10; k = 0:n-1; % n is the number of terms
F = 4/pi * (1./(2*k+1)) * sin(((2*k+1)'*pi*t)/T);
plot(t,F)
  3 件のコメント
Michael Golden
Michael Golden 2017 年 3 月 15 日
Awesome! Many thanks!!
Iyad Khuder
Iyad Khuder 2020 年 11 月 12 日
That's amazing! Many thanks!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by