Professional Documents
Culture Documents
lker Bayram
1679695 08.03.2011
______
>> digits(4)
>> N=1765;
>> sum=vpa(0);
>> for n=N:-1:1 ;
sum=vpa(sum+(1/n)^2);
end, sum
sum =1.644 ______
After we find results we compute (pi^2)/6
>> (pi^2)/6;
>> ans
ans = 1.6449
we see that they have the same accuracy for 4 digits.
2)
a- First we shall look for e^-5:
>> exp(-5);
>> ans
ans = 0.0067
When we do calculation in i :
>> N=9;
sum=vpa(0);
for n=0:N;
sum=vpa(sum+((-1^n)*(5^n))/factorial(n));
end, sum
sum =-143.68945656966490321597319283654
It is clearly not accurate, and we compute the one in ii :
>> N=9;
>> sum=vpa(0);
>> for n=0:9;
sum=vpa(sum+(5^n)/factorial(n));
sum2=1/sum;
end, sum2
sum2 =0.0069594528636495356903081306788982
We see that the second way is more accurate than the first one.
K=6
x is also given: x=1 We must remove digits and vpa statements, so we can use format long to see
clearly.
i)
To determine e to K decimals:
>> format long
>> K=6;
told=(1/2)*10^(-K);
Nmax=10000;
sum=1;
for n=1: Nmax;
a=1/factorial(n);
if a<told;
break;
end;
sum=sum+a;
end, sum
sum =2.718281525573192
ii)