Presentation is loading. Please wait.

Presentation is loading. Please wait.

Numerical Computation

Similar presentations


Presentation on theme: "Numerical Computation"— Presentation transcript:

1 Numerical Computation
Lecture 16: Numerical Integration United International College

2 Last Time During the last class period we covered:
Numerical Approximations to Derivatives Readings: Pav, Chapter 7

3 Today We will cover: Numerical Integration (Quadrature) Readings:
Pav, Chapter 8, sections Moler,

4 The Definite Integral The definite integral is the total value or
summation of f(x) over a range of x. The integration symbol is actually a stylized capital S intended to signify the connection between integration and summation.

5 The Definite Integral f(x) a b x

6 Upper, Lower Sums We approximate the definite integral by splitting the interval from a to b into n subintervals a = x0 < x1 < x2 < < xn-1 < xn = b This is called a partition P of [a,b]. On each subinterval [xi-1 ,xi ] define the smallest value of f(x) to be mi and the largest value of f(x) to be Mi . mi = min{ f(x) | xi-1 < x < xi } Mi = max{ f(x) | xi-1 < x < xi }

7 Upper, Lower Sums Then, we can define Lower and Upper approximating
sums for the integral:

8 Upper, Lower Sums Definition: A function f(x) is Riemann-integrable over [a,b] if over all possible partitions P. Here the words “sup” and “inf” can be thought of as the same as maximum and minimum. Theorem (from calculus): If f(x) is continuous on [a,b], then it is Riemann-integrable on [a,b]

9 Upper, Lower Sums Note: While this is a good definition, in practice it is often hard to find the max and min of f(x) on each subinterval. Idea: Use a simpler approximation that is between the Upper and Lower approximations.

10 Simple Trapezoidal Rule
Over a single interval [a,b] we can approximate f(x) by a line and find the area under this line. This area looks like a trapezoid.

11 Simple Trapezoidal Rule
The area under this trapezoid is just

12 Composite Trapezoidal Rule
To get a better approximation for f(x) over [a,b] we create a partition with equal sized subintervals: a = x0 < x1 < x2 < < xn-1 < xn = b with the width of every subinterval = h. That is, xi+1 - xi = h for all i. Adding up all the trapezoidal areas we get

13 Composite Trapezoidal Rule
Factoring out the h we get This is the Composite Trapezoidal Rule

14 Composite Trapezoidal Rule
Example: Approximate using the composite trapezoidal rule with n=4. Solution: h = (2-0)/4 = ½. Partition is 0 < 0.5 < 1.0 < 1.5 < Trapezoidal Rule gives

15 Error in Trapezoidal Rule
Theorem: (Section in Pav) Proof: (Read section in Pav) Note: The trapezoidal rule will be exact (no error) if the function f(x) is linear. (Why?)

16 Simple Midpoint Rule The area defined by a rectangle of height f((a+b)/2) is a (a+b)/2 b

17 Composite Midpoint Rule
Create a partition: a = x0 < x1 < x2 < < xn-1 < xn = b with the width of every subinterval = h. Adding up all the midpoint areas we get This is the Composite Midpoint Rule

18 Simple Simpson’s Rule Instead of using linear approximations to f(x), we can use a 2nd order Lagrange polynomial approximation L(x). To do this, we will need three points, a,b, and x1 halfway between a and b. L(x) f(x) a=x0 c=x1 b=x2

19 Simple Simpson’s Rule The area under L(x) can be an approximation to the integral

20 Simple Simpson’s Rule After integrating and simplifying we get

21 Composite Simpson’s Rule
Create a partition with an even number of subintervals: a = x0 < x1 < x2 < < xn-1 < xn = b with the width of every subinterval = h. On every pair of subintervals, [x0 , x1], [x1 , x2 ], etc, we use Simpson’s Rule: f(x) …... x x0 h x1 h x2 h x3 h x4 xn-2 xn-1 xn

22 Composite Simpson’s Rule
We get:

23 Composite Simpson’s Rule
Simplifying, we have This is the Composite Simpson’s Rule Note: The error in Simpson’s rule is O(h4)

24 Matlab – Trapezoidal Rule
function sum = trapezoid( f, a, b, n ) % trapezoid computes the trapezoidal rule % approximation to f(x) over [a,b] using n % equally spaced subintervals h = (b-a)/n; x = a + (h .* (0:n)); % vector of partition x values sum=0.0; for i = 1:n sum = sum + (h/2.0)*(f(x(i)) + f(x(i+1))); end

25 Matlab – Trapezoidal Rule
>> trapezoid(inline('x^2'),1,2,64) ans = 2.3334

26 Romberg Integration Idea: Use the Richardson Extrapolation technique to improve integral approximations. Consider the Trapezoidal Rule using 2n subintervals of [a,b]. Then, h = (b-a)/ 2n and the approximation will be We know that this approximation has error O(h2). Thus,

27 Romberg Integration This is exactly the kind of expression we had for Richardson Extrapolation in Chapter 7. Let

28 Romberg Intergation Compute the table of values:
This is called Romberg Integration

29 Romberg Intergation Example: Approximate The exact value =

30 Romberg Intergation Note: In the column for m=1 we have
If we calculate this out, we get exactly the Simpson’s Rule approximations for the integral.


Download ppt "Numerical Computation"

Similar presentations


Ads by Google