This question is closed.
What I have right now.
X=pi/2; sum = 0 N =[3 10 25]; %I want the sum of the first 3 terms, the sum of the first 10 terms, etc. for n = 1:N sum = sum + (((-1)^n)/n)*sin(n*X) end sum
This only seems to sum the first 3 terms. Is there a way to do this at the same time. I can can do this three times separately, but I wanted a more compact way to write this. Any help would be greatly appreciated.
Oh, you made a serious effort. Lots of ways to do it of course. (BTW, NEVER use sum as a variable name!!!!!)
X = pi/2; N = [3 10 25]; n = 1:max(N); seriesterms = (((-1).^n)./n).*sin(n*X) partialsums = cumsum(seriesterms); partialsums = partialsums(N);
So no explicit loop there. Since you used sum, I assume cumsum is equally valid to use. ;-) Anyway, you never said cumsum was disallowed.
There is nothing wrong with use of a loop of course.