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.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터 및 File Exchange에서 Function Creation에 대해 자세히 알아보기

태그

질문:

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