Summation of a series without for loop

조회 수: 2 (최근 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 CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by