Ok so I'm not allowed to delete this question but i figured out that it works if I use symsum. In case someone else wants to know how this was solved, here it is, and in case you can't tell, using 100 for the range of m doesn't give the best approximation
Finding the sum of a series
6 views (last 30 days)
Show older comments
Hey! This is probably a "stupid" question with an easy obvious answer but I've looked at all kinds of online examples of getting the sum of a series in Matlab and just can't figure out why I'm getting the wrong result.
This is the series I'm using to approximate pi and here is my latest attempt at code for it

*I realize 10 is a really small range for m, part of what I'm doing is showing how using a smaller to larger range changes the approximation. But no matter what I plug in I haven't yet found a way to put it into the series that actually works
Answers (1)
Kirby Fears
on 18 Sep 2015
Edited: Kirby Fears
on 18 Sep 2015
Your code works fine, but you forgot about the k=0 term in your summation. I've simplified your summation somewhat, but the only change in methodology is to add 1 inside of the sum (the k=0 term).
pi=4*(1+sum(((-1).^m)./(2*m+1)));
With m=1:100, I get the following pi value:
pi =
3.1515
Hope this helps.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!