Math 541 - Numerical Analysis Joseph M. Mahaffy, jmahaffy@mail.sdsu.edu Department of Mathematics and Statistics Dynamical Systems Group Computational Sciences Research Center San Diego State University San Diego, CA 918-770 http://jmahaffy.sdsu.edu Spring 018 (1/4)
Outline 1 Definitions Taylor s Theorem (/4)
Why Review Calculus??? Definitions Taylor s Theorem It s a good warm-up for our brains! When developing numerical schemes we will use theorems from calculus to guarantee that our algorithms make sense. If the theory is sound, when our programs fail we look for bugs in the code! (3/4)
Definitions Taylor s Theorem Background Material A Crash Course in Calculus Key concepts from Calculus Limits Continuity Differentiability Taylor s Theorem (4/4)
Limit Definitions Taylor s Theorem The most fundamental concept in Calculus is the limit. Definition (Limit) A function f defined on a set X of real numbers X R has the limit L at x 0, written lim f(x) = L x x 0 if given any real number ɛ > 0, there exists a real number δ > 0 such that f(x) L < ɛ whenever x X and 0 < x x 0 < δ. (5/4)
Continuity Definitions Taylor s Theorem Definition (Continuity (at a point)) Let f be a function defined on a set X of real numbers, and x 0 X. Then f is continuous at x 0 if lim f(x) = f(x 0 ). x x 0 It is important to note that computers only have discrete representation, not continuous. Thus, the computer is often making approximations. (6/4)
Derivative Definitions Taylor s Theorem Definition (Differentiability (at a point)) Let f be a function defined on an open interval containing x 0 (a < x 0 < b). f is differentiable at x 0 if f (x 0 ) = lim x x 0 f(x) f(x 0 ) x x 0 exists. If the limit exists, f (x 0 ) is the derivative at x 0. Note: This is the slope of the tangent line at f(x 0 ). The derivative is used often in this course, and sometimes an approximate derivative is adequate. (7/4)
Taylor s Theorem Definitions Taylor s Theorem The following theorem is the most important one for you to remember from Calculus. Theorem (Taylor s Theorem with Remainder) Suppose f C n [a, b], f (n+1) exists on [a, b], and x 0 [a, b]. Then for all x (a, b), there exists ξ(x) (x 0, x) with f(x) = P n (x) + R n (x) where P n (x) = n k=0 f (k) (x 0 ) (x x 0 ) k, k! R n (x) = f (n+1) (ξ(x)) (x x 0 ) (n+1). (n + 1)! P n (x) is called the Taylor polynomial of degree n, and R n (x) is the remainder term (truncation error). Note: f (n+1) exists on [a, b], but is not necessarily continuous. (8/4)
Important Important : Below are important functions studied in Calculus e x = cos(x) = sin(x) = x n n! ( 1) n x n (n)! ( 1) n x n+1 (n + 1)! (9/4)
Example 1: Approximate sin 1 Example 1: Approximate sin(x) with x near π 6 We know sin ( ) π 6 = 1, so what about sin ( π 6 + 0.1) Since f(x) C (, ), we can use Taylor s theorem: f(x) = f(x 0 ) + f (x 0 )(x x 0 ) + 1! f (x 0 )(x x 0 ) +... = 1 n! f (n) (x 0 )(x x 0 ) n (10/4)
Example 1: Approximate sin From Taylor s theorem sin(x) with x near π 6 1 d n sin(x) = n! dx n sin(x) x= π 6 = ( π ) ( π ) ( = sin + cos x π 6 6 6 1 ( π ) (! sin x π 6 6 But sin ( ) π 6 = 1 and cos ( ) π 6 = 3 ( x π ) n 6 ) ) 1 3! cos ( π 6 ) ( x π 6 ) 3 +... (11/4)
Example 1: Approximate sin 3 With information above and x = π 6 + 0.1, we have sin(x) = 1 3 + = 1 [ 1 1 ( x π ) 1 +! 6 4! [ ( x π ) 1 6 3! ( 1) n (n)! ( x π ) ] 4... 6 ) ] 3 +... ( x π 6 ( x π ) n 3 + 6 It follows that sin ( π 6 + 0.1) satisfies: ( π ) sin 6 + 0.1 = 1 ( 1) n (n)! (0.1)n + 3 ( 1) n ( x π ) n+1 (n + 1)! 6 ( 1) n (n + 1)! (0.1)n+1 (1/4)
Example 1: Approximate sin 4 Examining the infinite sums, we see both the (0.1) n and the factorials in the denominator resulting terms going to zero We truncate the series at n = N, gives the approximation at x = π 6 + 0.1 ( π ) sin 6 + 0.1 1 N ( 1) n 3 (n)! (0.1)n + N ( 1) n (n + 1)! (0.1)n+1 Truncating the series at n = N leaves a polynomial of order N + 1 T N (x) = 1 N ( 1) n (n)! where x is close to π 6 ( x π ) n 3 + 6 N ( 1) n ( x π ) n+1, (n + 1)! 6 (13/4)
Example 1: Approximate sin 5 The error or remainder satisfies: R N (x) = 1 n=n+1 ( 1) n (n)! ( x π ) n+ 3 6 n=n+1 Thus, sin ( π 6 + 0.1) = T N ( π 6 + 0.1) + R N ( π 6 + 0.1) ( 1) n ( x π ) n+1, (n + 1)! 6 If we use the approximation from the previous page with x = π 6 + 0.1, we find the following polynomial evaluations: Poly Order Approximation Error sin ( π ( 6 + 0.1) 0.58396036 T π 1 ( 6 + 0.1) 1 0.5866054 0.4546% T π ( 6 + 0.1) 3 0.5839580-0.00037% T π 3 6 + 0.1) 5 0.58396036 8.56 10 8 % (14/4)
Example 1: Approximate sin 6 Below is the graph of y = sin(x) with the Taylor polynomial fits of order 1, 3, and 5, passing through x 0 = π 6 1.5 1 sin(x) T1(x) T(x) T3(x) x0 sin(x) 0.5 y 0 0.5 1 1.5 π/ π/3 π/6 0 π/6 π/3 π/ x We observe even a cubic polynomial fits the sine function well (15/4)
Example 1: Approximate sin 7 The remainder term in Taylor s theorem is useful for finding bounds on the error. Recall R n (x) = f (n+1) (ξ) (n + 1)! (x x 0) (n+1) with ξ (x 0, x). However, we rarely know ξ. A bound on the error satisfies max R n(x) = max x [x 0 δ,x 0+δ] x [x 0 δ,x 0+δ] f (n+1) (ξ) x x 0 (n+1) (n + 1)! δ n+1 max (n + 1)! f (n+1) (ξ) x [x 0 δ,x 0+δ] (16/4)
Example 1: Approximate sin 8 For this example, the (n + 1) st derivative of f(x) = sin(x) satisfies f (n+1) (ξ) 1, and we are taking δ = 0.1 It follows that max R n(x) x [x 0 δ,x 0+δ] δ n+1 max (n + 1)! f (n+1) (ξ) x [x 0 δ,x 0+δ] δ n+1 (n + 1)! (0.1)n+1 (n + 1)! We saw the error for T (x) (cubic fit) was.16 10 6. The error approximation gives E 3 (x) (0.1)4 4! which is only double the actual error 4.17 10 6, (17/4)
Example : Integrate cos(cos(x)) 1 Example : Consider the following integral: π 0 cos(cos(x))dx This is not an integral that is readily solvable with standard methods Can we obtain a reasonable approximation? Maple and MatLab can numerically solve this problem Later in the course we learn quadrature methods for solving Polynomials are easy to integrate, so let s try using Taylor s theorem and integrate the truncated polynomial. (18/4)
Example : Integrate cos(cos(x)) Our function is clearly C (, ), so Taylor s theorem readily applies 1 d n f(0) f(x) = cos(cos(x)) = n! dx n xn There is no easy form for dn f(0) dx, but taking a few terms is not hard n f(0) = cos(cos(0)) = cos(1) f (0) = sin(cos(0)) sin(0) = 0 f (0) = cos(cos(0)) sin (0) + sin(cos(0)) cos(0) = sin(1) It follows that a quadratic approximating polynomial is: f(x) P (x) = cos(1) + sin(1) x 0 (19/4)
Example : Integrate cos(cos(x)) 3 The integral gives the area under the curve. The figure below shows f(x) = cos(cos(x)) and the second order Maclaurin series expansion P (x) = cos(1) + sin(1) x f(x) P(x) f(x) = cos(cos(x)) 1.5 y 1 0.5 0 0 π/4 π/ x (0/4)
Example : Integrate cos(cos(x)) 4 The nd order Maclaurin series expansion P (x) = cos(1) + sin(1) x is easily integrable π 0 cos(cos(x))dx = π 0 ( cos(1) + sin(1) ) x dx (cos(1)x + sin(1)x3 = π cos(1) 6 + π3 sin(1) 48 ) π 0 1.3965, which is larger than the actual value (1.01970) as seen in the graph. This is a 15.8% error, so not great. (1/4)
Example : Integrate cos(cos(x)) 5 How much is the error improved if the interval is divided into two equal intervals? This time we use Taylor s expansions around x 0 = 0 and x 0 = π 4, and again truncate with nd order polynomials About x 0 = π 4, Taylor s series is ( ) ( ) sin T (x) = cos + ( ) ( sin cos + 4 0.7604 + 0.45936 4 ( x π ) 4 ) ( x π 4 ) ( x π ) ( + 0.03960 x π ) 4 4 (/4)
Example : Integrate cos(cos(x)) 6 The integral is now approximated by π 4 0 where π cos(cos(x))dx + cos(cos(x))dx π 4 P (x) 0.54030 + 0.4074 x and ( T (x) 0.7604 + 0.45936 x π 4 π 4 0 π P (x)dx + T (x)dx, π 4 ) + 0.03960 ( x π ) 4 However, integrating these quadratic polynomials is easy π 4 0 π P (x)dx + T (x)dx 0.4997 + 0.74517 = 1.37469, π 4 which is only a.95% error from the actual value (3/4)
Example : Integrate cos(cos(x)) 7 The figure below shows a diagram for the computations done above with two approximating quadratics for finding the area f(x) = cos(cos(x)) 1.5 1 f(x) P (x) T (x) y 0.5 0 0 0.7854 1.5708 x (4/4)