pi approximation using a series

7 ビュー (過去 30 日間)
Fe99
Fe99 2021 年 1 月 16 日
編集済み: Fe99 2021 年 1 月 16 日
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.
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

採用された回答

KSSV
KSSV 2021 年 1 月 16 日
x = 0 ;
n = 0 ;
while ~(abs(pi-x) <= 10^-4 )
x = x+4*(-1)^n/(2*n+1) ;
n = n+1 ;
end
  1 件のコメント
Fe99
Fe99 2021 年 1 月 16 日
編集済み: Fe99 2021 年 1 月 16 日
Thanks!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by