pi approximation using a series
1 次查看(过去 30 天)
显示 更早的评论
Write a function that will use a series to calculate the value of π. Follow so many articles until the contribution of the last article is lower than 10^-4.Call the function and compare it with matlab function pi.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/490060/image.png)
i tried it like this but it is far from correct.:
x=0;
sum=PI(x)
matlab=exp(x)
function [sum]=PI(x)
n=0;
N=(4*((-1)^i))/(2*i + 1);
sum=clen;
x=x+1;
while N>=10^(-4)
n=n+1;
N=(4*((-1)^i))/(2*i + 1);
sum=sum+N;
end
end
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!