Summation with FOR Loop
조회 수: 46 (최근 30일)
이전 댓글 표시
Hello, Super noob question, but how do I do the attached picture in MatLab using a FOR loop. I just need to know how to set up the loop, not the actual values. Thanks for any help!

댓글 수: 0
채택된 답변
Torsten
2017년 4월 18일
omega=...;
t=...;
N=...;
summe = 0.0;
for k=1:N
summe = summe + sin(omega*t*(2*k-1))/(2*k-1);
end
Best wishes
Torsten.
댓글 수: 2
Torsten
2017년 4월 19일
Try
t=0:2/pi/100:2/pi
omega=1;
N=1000;
summe = 0.0;
for k=1:N
summe = summe + sin(omega*t*(2*k-1))/(2*k-1);
end
plot(t,4/pi*summe)
Best wishes
Torsten.
추가 답변 (3개)
Jan
2017년 4월 17일
You cannot run a loop from 1 to infinity in Matlab. Either solve the summation symbolically or find out, if this sum converges and you can use a certain number of elements to get the result with a wanted accuracy.
Arzu Ahmadova
2019년 5월 22일
Hi,
Could you explain please how to code more than 2 different inifinite sums in loop?
daniel domshlak
2020년 3월 29일
i=0;
x = input ('choose the initial value : ');
y = input ('choose final value : ');
n=(x:y);
summe=0;
for i=x:y
a=(i*2+1).^3;
summe = summe + a;
end
summe
댓글 수: 3
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!