Finding the sum of a series

6 views (last 30 days)
Paulogna
Paulogna on 18 Sep 2015
Edited: Kirby Fears on 18 Sep 2015
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
  1 Comment
Paulogna
Paulogna on 18 Sep 2015
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

Sign in to comment.

Answers (1)

Kirby Fears
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.

Categories

Find more on Mathematics in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!