How do I approximate the value of pi

6 ビュー (過去 30 日間)
Dorothy Carter
Dorothy Carter 2015 年 11 月 8 日
編集済み: Real Name 2015 年 11 月 9 日
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)]);
  1 件のコメント
Dorothy Carter
Dorothy Carter 2015 年 11 月 8 日
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.

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

採用された回答

Real Name
Real Name 2015 年 11 月 8 日
Are you attempting to use the Leibniz series to approximate pi? That formula you have is not correct.
  2 件のコメント
Dorothy Carter
Dorothy Carter 2015 年 11 月 8 日
編集済み: Dorothy Carter 2015 年 11 月 8 日
What is the formula then? That was what I was given Changed script: 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.
Real Name
Real Name 2015 年 11 月 9 日
編集済み: Real Name 2015 年 11 月 9 日
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.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by