Posted by: santosh1984 January 28, 2010
Login in to Rate this Post:
0
?
Here is the code. It is perfectly running and does converge to 3.1416 for e=10^-8 with N= 63661979. Do the same for 10^-1 thru 10^-8. Hope you know how to make plots after this. Make sure the name of mat-file is pii.m and enjoy!!!!
function pii
clc
N=2;
pii=((-1)^2)/(0.5*1-0.25);
e=1;
while e>=10^-8;
pii_old=pii;
k=N;
pii1= ((-1)^(k+1))/(0.5*k-0.25);
N=N+1;
pii=pii_old+pii1;
e=abs(pii-pii_old)/pii_old;
end
pii_old
pii
N
e