# How do I approximate the value of pi

4 views (last 30 days)

Show older comments

Here is what I have so far:

function numberPI=(-1^n)*1/(2*n+1)*3^n

s=0;

n=input('enter value of n= ');

for i=1:n

s=s+i

numberPI

end

disp(['numberPI= ',num2str(numberPI)]);

### Accepted Answer

Real Name
on 8 Nov 2015

##### 2 Comments

Real Name
on 9 Nov 2015

Edited: Real Name
on 9 Nov 2015

The formula is given here:

https://en.wikipedia.org/wiki/Leibniz_formula_for_%CF%80

SUM (-1)^n/(2n+1) = pi/4

So make sure to multiply the final result by 4. I'm not sure why you were given that formula. You should confirm with whomever your instructor is.

### More Answers (0)

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!