Hi! I need to change the equation in this function!

조회 수: 3 (최근 30일)
Anthony Fuentes
Anthony Fuentes 2016년 10월 19일
편집: Adam 2016년 10월 19일
Hi! I need help with this function. I need to change the equation of Leibniz (pi/4=(1-1/3+1/5-1/7+1/9...-) to this one (pi/2= 2/1 2/3*4/3*4/5*6/5...) [Wellis Product]. The objective to the function is the following: Implement the Wellis' equation in a function that receives the relative error willing to accept and return the user a vector with all values of π and other vector estimated with relative errors associated with each value of π. The function is done with the Leibniz, but I dont know how to change it with the Wellis equation because a multiplication. The function that I have is the following (The function is in arrays): Thanks a lot!
function [ES,ER]=pi2array(x)
%ES is the array of estimated values of pi and ER is the error associated with each value of pi
RT=pi;
ter=0;
estimado=1;
er=2*x;
ER = [] ;
ES = [];
while er>=x
z=((1^(ter)+(ter+1))/(ter+1))^((-1)^ter);
estimado=(estimado*z);
es=estimado* 2;
er=100*abs((es-RT)/RT);
ter=ter+1;
ES(ter) = es ;
ER(ter) = er ;
end
end

답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by