Thursday, February 16, 2012

3.6

Evaluate e^-5 using two approaches

 Equation 1
e^ -x = 1 - x + x^2/2 - x^3/3! +......
 Equation 2
1/(e^ -x = 1 + x + x^2/2 + x^3/3! +......)

The actual value of e^5 is 6.737947 * 10^-3



Compute error of each method for 20 terms and compare

n = (0:19); 
x= 5; 
signs = (-1).^n; 
x2n = x.^n ; 
enx = cumsum(signs.* x2n./factorial(n));% eq1
epx = 1../(cumsum(x.^n ./factorial(n)));% eq2

m=1:.001:10;
true = 6.737947 * 10^-3 ;
hold on
plot(enx); %eq1
plot (epx, 'r');% eq2(red)
plot(m,true); 

hold off


The equation in blue is the first equation, the second is in red. They both converge around 15, but the second gets close sooner

No comments:

Post a Comment