While loop not ending
显示 更早的评论
Hello all, this is my first post on here so please forgive me if I do something wrong.
I am working on homework for one of my courses where I need to calculate how many terms of the arctangent taylor series approximation are needed to produce six significant figures of pi according to the scarborough criteria (relative error is less than .5*10^(-m) where m is the number of significant figures). Upon running my loop for around five minutes multiple times I have ended it and manually check my value for the relative error and found it to be around 7*10^(-11). My code is as follows:
%use pi=4.0atan(1) and the taylor series expansion for arc tangent about x=0
%to calculate pi to six significant figures using the scarborough criteria.
a=2; e_a=10; x=1; pi_exper(1)=20;
while e_a>.0000005
arctan(a-1)=(-1)^(a)*x^(2*a-3)/(2*a-3);
pid4(a-1)=sum(arctan);
pi_exper(a)=4*pid4(a-1);
e_a=abs(pi_exper(a)-pi_exper(a-1))/abs(pi_exper(a));
a=a+1;
end
Can anyone tell me why this loop is not working? Thank you very much in advance!
Andrew
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!