3 0
xe x dx
I = xe x dx = xe x e x
Multiple Application of Trapezoidal Rule Formula:
N 1 2 4 8 1 Best t = 2.25% 90.385 55.276 44.839 42.098
3 0
=41 .17 1
I=
n 1 ba f ( x0 ) + f ( xn ) + 2 f ( xi ) 2n i =1
O(h4)
16 1 I m Il 15 15
O(h6)
64 1 Im Il 63 63
4 0.0004% 41.171
2.
a. (20 points) Employ Lagrange Interpolation (Slide #10 in CHAP-23e.ppt) to determine the first derivative of y = 2 x 4 6 x 3 12 x 8 at x = 0 based on values at x0 = 0.5 , x1 = 1 , and x2 = 2 . Calculate the true value and the true (%) relative error. b. (15 points) Calculate the first derivative at x = 0 using a centered difference approximation (O(h2) error) based on h = 1 and equally spaced data. Calculate true (%) relative error. Compare the results obtained in part (a) and (b) and try to explain why one is better than the other.
Solution a. The true value: f ' (0) = 8(0) 3 18(0) 2 12 = 12 Given the data: x0 = 0.5 f(x0) = 1.125 x1 = 1 f(x1) = 24 x2 = 2 f(x2) = 48 Using Lagrange interpolation, we compute the derivative as:
f ' (0) = 1.125 2(0) 1 2 2(0) (0.5) 2 2(0) (0.5) 1 + ( 24) + ( 48) ( 0.5 1)(0.5 2) (1 ( 0.5))(1 2) ( 2 ( 0.5))(2 1) = 0.9 24 + 9.6 = 13.5
True percent relative error = | (-12+13.5)/-12|*100 = 12.5% b. Centered difference: f ' (0) = f ( x = 1) f ( x = 1) 24 12 = = 18 1 (1) 1 (1)
Since the original function is a 4th order polynomial, the best error (zero) is obtained if we interpolate the function with a 4th order polynomial and take the derivative of it. In other words, the higher the order of the interpolations, the smaller the error. Even though centered difference formula has O(h2) error rate, we can safely assume that it uses a 1st order approximation. Therefore, 2nd order Lagrange achieves a better error rate. Another reason for poor performance of centered formula is the high step size (h=1).
3.
a. (25 points) Use Heuns method with h = 0.5 to solve the following initial-value dy = yx 2 1.1y where y(0) problem numerically over the interval from x = 0 to 2: dx = 1. Iterate the corrector to s = 1%. b. (10 points) Plot your results.
(Note: since each step may involve several iterations, use of Excel or MATLAB is recommended)
Solution: a. For Heuns method, the value of the slope at x = 0 can be computed as which can 1.1 be used to compute the value of y at the end of the interval as
y (0.5) = 1 + (0 1.1(1))0.5 = 0.45
j
0 1 2 3 4
yi j
0.45 0.6294 0.5913 0.5994 0.5976
a
28.5% 6.45% 1.35% 0.288%
xi 0 0.5 1 1.5 2
b. The results along with the analytical solution are displayed below:
3 2 1 0 0 1 2