I would want to ask,which is the function,which can canculate the number π from series of Leibniz and 2 of Euler and the error |y- π| ?

1 件のコメント

darova
darova 2020 年 4 月 27 日
THere is no such built-in function. Write your own: LINK

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

回答 (1 件)

Ameer Hamza
Ameer Hamza 2020 年 4 月 27 日

0 投票

This one is for Leibniz
N = 100; % number of terms
den = 1:2:2*N-1;
signs = (-1).^(0:N-1);
terms_leibniz = 4./den.*signs;
pi_leibniz = cumsum(terms_leibniz);
err_leibniz = abs(pi-pi_leibniz);
plot(pi_leibniz);
hold on
yline(pi);
This one is for Euler
N = 100; % num terms
terms_euler = 6./(1:N).^2;
pi_euler = sqrt(cumsum(terms_euler));
err_euler = abs(pi-pi_euler);
plot(pi_euler);
hold on;
yline(pi);

2 件のコメント

Apostolia Argyropoulou
Apostolia Argyropoulou 2020 年 4 月 27 日
Thank you very much!
Ameer Hamza
Ameer Hamza 2020 年 4 月 27 日
Glad to be of help.

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

カテゴリ

タグ

質問済み:

2020 年 4 月 27 日

コメント済み:

2020 年 4 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by