28
Numerical Integration (Calculating the area under a curve) 1

ME 330A - Notes - Topic 3 - Numerical Integration

  • Upload
    jrkling

  • View
    225

  • Download
    1

Embed Size (px)

DESCRIPTION

Notes

Citation preview

Conservation of Linear Momentum (Differential Form)

Numerical Integration(Calculating the area under a curve)12Integration is a pretty important part of engineering.

The total change in velocity during a time period t is calculated by integrating acceleration with respect to time.

The total change in position is calculated by integrating velocity with respect to time.

The total work done on an object is calculated by integrating the force with respect to position.

Graphical interpretation of the differential equations:

If we record the speed of our car frequently, we could estimate the total distance traveled through integration.3

The area under the v-t curve is the net displacement of the particle.

The area under the a-t curve is the net velocity change of the particle.

4There are many functions that are impossible to integrate analytically.

5Remember that an integral is the area under a curve.

We can calculate the area under a curve by breaking the total area into chunks and adding the subareas. This process is called numerical integration.

When we integrate analytically, we break the area into an infinite number of infinitesimally small chunks.

6The simplest method for numerical integration is Riemann summation.

In Riemann summation, we represent the area under the curve as N rectangles with width x and height f (x).

7The figure demonstrates left Riemann summation.

Overestimates the area when f (x) is decreasing. Underestimates the area when f (x) is increasing.

8We can perform right Riemann summation too.

Underestimates the area when f (x) is decreasing. Overestimates the area when f (x) is increasing.

89Middle Riemann summation usually provides a better estimate of the area.

10The error in the Riemann summation methods decrease as the N increases.

11Using rectangles to estimate the area under a curve provides a pretty rough estimate of the area unless a lot of rectangles are used.

This is because horizontal lines provide a very poor fit to a curve (except where the curve is nearly horizontal).

Sloped lines, parabolas, and higher degree polynomials provide better fits to a curve.

12In the Trapezoidal Rule method, the curve is estimated as a diagonal line between the discretization points.

13If we add up all the areas,

14 Underestimates area when curve is concave down. Overestimates area when curve is concave up. Accuracy is enhanced with smaller x. Higher accuracy for same x compared to Riemann summation.

15Interesting note: If we average the left and right Riemann summations, use will obtain the Trapezoidal Rule.

Adding two lower accuracy estimates yields a higher accuracy estimate. This is the idea behind Romberg Integration (which we wont cover).

16Riemann summation uses one point to estimate the curve shape.

The Trapezoidal Rule method uses two points.

Simpsons Rule method uses three points (a parabola) to estimate the curve shape.

Higher degree polynomials and other integration schemes can be can be used (see Romberg Integration), but Simpsons Rule usually is sufficiently accurate.

Left RiemannTrapezoidalParabola

17In the Simpsons Rule method, each parabola is fit to 3 points in an interval (two endpoints and midpoint)

These points are relabeled with indices k1, k, k+1.

Parabola

18The parabola passes through the point (xk, fk) and so must have the form of

Evaluate this function at xk-1 and xk+1 ,

P(x)

19Using the relationship

Adding the two equations,

Subtracting the two equations,

20The equation for a parabola that passes through the function f (x) at the endpoints and midpoint of an interval is,

The area under the parabola is obtained through integration.

Evaluating the result at the limits of integration and utilizing the relationship

21The area under one parabola is,

Using our original notation,

Lets look at a simple example with three parabolas.

The area of each parabola is 22

23A pattern emerges,

24We assumed that all intervals are equally spaced, but often it is advantageous to use smaller intervals when the function changes rapidly and larger intervals when the function changes smoothly.

For ME 330A, we will use a fixed interval size.

25We have learned about five methods of numerical integration

Simpsons Rule requires more calculations at a given x, but it is more accurate for the same x .

26If a 2nd degree polynomial (Simpsons Rule) is pretty accurate, wouldnt a higher degree polynomial be even more accurate?

Yes, but more calculations are required. Usually Simpsons Rule method is sufficient.

Left RiemannTrapezoidalSimpsons4th degree polynomial27How many discretizations are enough?

First, establish how much error () in the area you are comfortable with. 10%? 1%? 0.01%? 0.0001%?

Calculate the area for N discretizations (x), ANCalculate the area for 2N discretizations (x/2), A2NIf |(A2N AN)/AN|< , you are done. If |(A2N AN)/AN|> , halve the interval size and try again.

28Matlab allows you to numerically integrate using the quad( ) function. Place the function in single quotes.

To calculate the integral of x3ex from 0 to 2,

>> quad('x.^3.*exp(x)', 0, 2)

FUTURE ADJUST TOLERANCE IN QUAD()