フィルターのクリア

Madhava approximation of pi

3 ビュー (過去 30 日間)
KayLynn
KayLynn 2013 年 10 月 26 日
コメント済み: sixwwwwww 2013 年 10 月 26 日
I am trying to approximate the value of pi using the equation Madahava of Sangamagrama used.
The code that I have so far is:
function [ output_args ] = madhavapi(m)
%This function will takes N as input and returns an approximation for pi.
k=[0 1 2 3 4]
1./(-3).k
[1/(-3)^0/(-3)^1/(-3)^2;
1./(2.*k-1)
1./sum*12
end
I am not sure how to conclude this code. When I try to execute the above code, I do not get any answer.
  3 件のコメント
KayLynn
KayLynn 2013 年 10 月 26 日
I wouldnt know that. Are you able to help me with the last statement or so of this code. I am basically seeking help with the way to end this code in order to get an output that results in approximating pi.
Walter Roberson
Walter Roberson 2013 年 10 月 26 日
編集済み: Walter Roberson 2013 年 10 月 26 日
You did not assign anything to "output_args"
"sum" is a function, not a variable.
You do not use "m" anywhere in your function.
The expression
1./(-3).k
is not valid. There is no "." operator in MATLAB.

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

採用された回答

sixwwwwww
sixwwwwww 2013 年 10 月 26 日
Dear Kaylynn, here is the function which approximates value of pi using Madahava Sangamagrama equation:
function [ output_args ] = madhavapi(m)
k = 0:m;
output_args = 4 * sum((-1).^k ./ (2 * k + 1));
end
I hope it helps. Good luck!
  2 件のコメント
KayLynn
KayLynn 2013 年 10 月 26 日
I want to take an input N and return the approximate value of pi. For example if my N equals 2, I should get an output of 3.152 right?
sixwwwwww
sixwwwwww 2013 年 10 月 26 日
To take 'N' change the first two lines of above code as:
function [ output_args ] = madhavapi(N)
k = 0:N;
and here is the link which describes Madahava Sangamagrama equation: http://en.wikipedia.org/wiki/Leibniz_formula_for_%CF%80. So according to this equation if you put N = 2 then you will get output 3.46666666666667. As you will increase the value of N then output will come close to well known value of pi: 3.1415...

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by