I have already written the following program using wallis' algorithm for continued fraction expansion, but when I compare it to the actual value of arctan the error is high. I thought that there was something wrong w/ starting k at 1 and going to n because the first term in an arctan continued fraction expansion is x not x^2. So I tried to take the first terms out and start k at 2, but I'm still having trouble. Any suggestions?
function f=arctancfe1(x,n)
b0=0; a1=x; b1=1; A1=x; B1=1; Akm2=1; Bkm2=0; Akm1=b0; Bkm1=1;
for k=2:n;
ak=k*k*x*x;
bk=2*k-1;
Ak=bk*Akm1+ak*Akm2;
Bk=bk*Bkm1+ak*Bkm2;
for j=1:n
Aj=Ak; Bj=Bk; f=Aj/Bj; end
Akm2=Akm1;
Akm1=Ak;
Bkm2=Bkm1;
Bkm1=Bk;
really good explanation of algorith here:http://books.google.com/books?id=1aAOdzK3FegC&pg=PA207&lpg=PA207&dq=wallis+algorithm+numerical+recipes&source=bl&ots=3iVgG9Gpnd&sig=LmrVzT4RUEEoOK7FgOWT5vEUrEg&hl=en&sa=X&ei=7zjgUrHRFefMsQTnqYDABA&ved=0CDYQ6AEwAg#v=onepage&q=wallis%20algorithm%20numerical%20recipes&f=false