You are on page 1of 3

HOMEWORK 1

lker Bayram
1679695 08.03.2011

1)We compute the right order and the reverse order.


>> digits(4)
N=1765;
sum=vpa(0);
>> for n=1:N ;
sum=vpa(sum+(1/n)^2);
end, sum
sum =1.644

______

>> 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.

b) First we must define K:


>> K = round(mean([1 6 7 9 6 9 5]))

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)

To determine e to K significant digits:


>> format long
>> K=6;
told=(1/2)*10^(1-K);
Nmax=10000;
sum=1;
for n=1:Nmax;
m=1/factorial(n);
if m<told;
break;
end;
sum=sum+m;
end, sum
sum = 2.718278769841270

You might also like