function numberPI s=0; n=input('enter value of n= '); for i=1:n s=s+i; numberPI=sqrt(12)* 1./((2*n+1).*(-3).^n; end disp(['numberPI= ',num2str(numberPI)]); Still an error.
How do I approximate the value of pi
1 次查看(过去 30 天)
显示 更早的评论
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)]);
采纳的回答
Real Name
2015-11-8
Are you attempting to use the Leibniz series to approximate pi? That formula you have is not correct.
2 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!