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

1 次查看(过去 30 天)
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