<<

Numerical approximation of definite

You should already be familiar with the left and right-hand Riemann sums used in the definition of the definite :

 b n−1 n and Differential Equations I I ≡ f (x) dx = lim f (xi )∆x = lim f (xi )∆x, a n→∞ n→∞ MATH 250 A i=0 i=1

where ∆x =(b − a)/n and xi = a + i ∆x. Numerical approximations The left and right rules respectively approximate the integral I with LEFT(n)andRIGHT(n), where

n−1 n LEFT(n)= f (xi )∆x, RIGHT(n)= f (xi )∆x, i=0 i=1

with ∆x and xi defined as above.

Link to Geogebra

Numerical approximations Calculus and Differential Equations I Numerical approximations Calculus and Differential Equations I

Numerical approximation of definite integrals (continued) Overestimates and underestimates

The midpoint rule consists in approximating the definite 1 Assume that f is increasing between a and b and that we  b integral by evaluating f at the midpoint between xi and xi+1: approximate I = a f (x) dx with LEFT(n). Which of the   following statements is correct? n−1 xi + xi MID(n)= f +1 ∆x. 1 LEFT(n) is an underestimate 2 i=0 2 LEFT(n) is an overestimate 3 LEFT(n)isexact The trapezoid rule approximates the under the graph of f between xi and xi+1 with the area of the corresponding 2 If f is increasing on [a, b], then trapezoid:  b   n−1 LEFT(n) ≤ f (x) dx ≤ RIGHT(n). f (xi )+f (xi ) TRAP(n)= +1 ∆x. a 2 i=0 3 Similarly, if f is decreasing on [a, b], then From the above formula, one can see that  b 1 ≤ ≤ . TRAP(n)= (LEFT(n)+RIGHT(n)) . RIGHT(n) f (x) dx LEFT(n) 2 a

Numerical approximations Calculus and Differential Equations I Numerical approximations Calculus and Differential Equations I Overestimates and underestimates (continued) Example of application

In order to ensure that TRAP(n)isanoverestimate,whichof the following requirements do we need? Assume that the f is positive, decreasing, and  b 1 f is increasing concave down on [a, b]. Let I = f (x) dx. 2 f is concave up a 3 f is concave down Assume that the values of LEFT(10), RIGHT(10), TRAP(10), 4 f is decreasing and MID(10) are, in random order, given by , If f is concave up on [a b], then 0.703, 0.724, 0.735, 0.745.  b MID(n) ≤ f (x) dx ≤ TRAP(n). Use the above to assign a value to each of LEFT(10), a RIGHT(10), TRAP(10), and MID(10).

Similarly, if f is concave down on [a, b], then Then, indicate which of the statements below is correct: 1 0.703 ≤ I ≤ 0.724  b 2 . ≤ ≤ . TRAP(n) ≤ f (x) dx ≤ MID(n). 0 724 I 0 735 a 3 0.735 ≤ I ≤ 0.745

Numerical approximations Calculus and Differential Equations I Numerical approximations Calculus and Differential Equations I

Approximation errors Numerical integration of ODEs

If we use a numerical method, say the left rule, to approximate dy = g(x, y) a definite integral I , we define the absolute error EL(n), as dx The above differential equation may formally be integrated as EL(n)=I − LEFT(n).  x+h y(x + h) − y(x)= g(t, y(t)) dt. x One can show that |EL(n)| and |ER (n)| are linear functions of 1/n. If we know y(x), a numerical approximation of y(x + h)may thus be obtained by finding an estimate of the integral in the Similarly, |ET (n)| and |EM (n)| decrease quadratically as n is right-hand-side of the above equation. increased. Euler’s method consists in assuming that g(t, y(t)) is This can be improved by using Simpson’s rule, given by constant on the interval [x, x + h], and equal to g(x, y(x)), where x is the left end-point of the interval. 1 SIMP(n)= (2 MID(n)+TRAP(n)) . We thus have 3 y(x + h)  y(x)+hg(x, y(x)). 4 One can show that the error |ES (n)| decreases like 1/n .

Numerical approximations Calculus and Differential Equations I Numerical approximations Calculus and Differential Equations I Numerical integration of ODEs (continued) Numerical error

dy = g(x, y) Numerical simulations are very powerful tools, but if we want dx to trust their predictions, it is essential to know their If we use the midpoint rule, then we obtain the modified Euler limitations. In particular, we need to be able to understand method mentioned in the lab, and control numerical errors.   h h All of the above methods are susceptible to two types of error: y(x + h)  y(x)+hg x + , y(x)+ g(x, y(x)) . 2 2 1 The discretization error is due to approximation errors in the numerical method. If we use the trapezoid rule,weobtainHeun’s method (sometimes also called improved Euler’s method) 2 The round-off error is due to the fact that a computer does not perform exact calculations. h For instance, in MATLAB, eps returns “the distance from 1.0 y(x+h)  y(x)+ (g(x, y(x)) + g(x + h, y(x)+hg(x, y(x)))) . 2 to the next largest double-precision number”.

Numerical approximations Calculus and Differential Equations I Numerical approximations Calculus and Differential Equations I

Discretization error Taylor

The discretization error has two sources: We now turn to the question of approximating a function of one 1 The local discretization error en, which is the error made at variable by polynomials. each time step due to the fact that we approximate an integral on the right-hand side of the equation: The Taylor − , en =˜yn y(xn) of degree n of the function f where y(xn) is the exact solution, andy ˜n is the numerical near x = a is a approximation of y(xn) assuming that y(xn−1)isknown exactly. polynomial that matches the value of 2 The global discretization error En, which is the error made on f and of its first n y(xn) when it is evaluated from an initial condition y0 after n derivatives at the numerical integration steps: point x = a.

− , En = yn y(xn) The figure above shows the graph of cos(x) and of the Taylor polynomials of degree up to 8 near x =0. where yn is the numerical solution obtained after n steps.

Numerical approximations Calculus and Differential Equations I Numerical approximations Calculus and Differential Equations I Taylor polynomials (continued) Numerical approximation of definite integrals revisited

The Taylor polynomial of degree n, centered at x = a,ofa  b n−1  x function f is given by  i+1 b − a f (x) dx = f (x) dx, xi = a + i∆x, ∆x = . − 2 − n a x n  (x a)  (x a) (n) i=0 i Pn(x)=f (a)+(x − a)f (a)+ f (a)+···+ f (a). 2! n! For the left rule, for each x ∈ [xi , xi+1], we have Of course, the above assumes that f has is at least n times  differentiable near a. In what follows, we assume that f is f (x)=f (xi )+(x − xi ) f (ξ(x)),ξ(x) ∈ (xi , x). smooth, for simplicity. From this formula, we see that if f  is positive and bounded One can show that the error made by replacing f by its Taylor by M between xi and xi+1,then polynomial of degree n is given by 0 ≤ f (x) − f (xi ) ≤ M(x − xi ), − n+1 (x a) (n+1) f (x)=Pn(x)+Rn(x), Rn(x)= f (ξ), which gives that LEFT is an underestimate and (n + 1)!     xi+1  xi+1 2   (∆x) where ξ ∈ (a, x).  f (x) dx − f (xi )∆x ≤ M (x−xi ) dx = M . xi xi 2 Link to d’Arbeloff Taylor Polynomials software

Numerical approximations Calculus and Differential Equations I Numerical approximations Calculus and Differential Equations I

Approximation errors Approximation errors (continued)

xi + xi For the midpoint rule, we have, with m = +1 , Finally, for the trapezoid rule, we have (by integration by 2 parts)  x  x  1 2  i+1 i+1 − − ξ ,ξ∈ , . xi  f (x)=f (m)+(m x) f (m)+ (x m) f ( (x)) (x) (xi x) f (x) dx =[(x − m)f (x)] +1 − (x − m) f (x) dx. 2 xi xi xi We can check that  We can use a Taylor expansion for f (x)nearx = m to see xi+1     f (m)+(m − x) f (m) dx = f (m)∆x, that if f is positive between xi and xi+1, then TRAP gives an xi overestimate.  so that if f is positive andboundedbyMbetweenxi and Moreover, the error over an interval of length ∆x is bounded 3  xi+1,then by M(∆x) /12, where M is the maximum of |f | over that interval. M 0 ≤ f (x) − f (m)+(m − x) f (m) ≤ (x − m)2, 2 For all of these methods, if the error on the integral between p+1 xi and xi+1 is of order (∆x) ,thenthe error on the integral which gives that MID is an underestimate and that the larger between a and b is of order 1/np,wheren is the number of | | f , the larger the error. sub-intervals.

Numerical approximations Calculus and Differential Equations I Numerical approximations Calculus and Differential Equations I Numerical integration of ODEs revisited

A numerical method is consistent if the local discretization error goes to zero as h → 0. A numerical method is convergent if the global discretization error goes to zero as h → 0. Typically, one uses Taylor expansions to decide whether a numerical method is consistent and convergent. A numerical method may also be unstable, in the sense that a numerical solution to y  = λy with λ<0 can display growth. These are topics typically discussed in an introductory course on numerical , such as MATH 475. Finally, one should keep in mind that a numerical method is a map of the form yn+1 = G(yn, n), and that if G is nonlinear, chaos may be observed.

Link to Chaos on the Web

Numerical approximations Calculus and Differential Equations I