Chapter 9 Numerical Integration Flow Charts, Loop Structures Copyright © The McGraw-Hill Companies,...

25
Chapter 9 Numerical Integration Flow Charts, Loop Structures Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Transcript of Chapter 9 Numerical Integration Flow Charts, Loop Structures Copyright © The McGraw-Hill Companies,...

Page 1: Chapter 9 Numerical Integration Flow Charts, Loop Structures Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Chapter 9Numerical Integration

Flow Charts, Loop Structures

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Page 2: Chapter 9 Numerical Integration Flow Charts, Loop Structures Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Concepts From Calculus

• Two fundamental operations:– Differentiation– Integration

• Differentiation: finding the rate of change (derivative) relative to a variable

• Integration: summing rates of change over an interval

• We will illustrate with linear position, velocity, and acceleration of a particle

Engineering Computation: An Introduction Using MATLAB and Excel

Page 3: Chapter 9 Numerical Integration Flow Charts, Loop Structures Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Linear Motion

• Consider this particle (note: in mechanics, the term particle does not relate to size. A particle is simply a body for which we can neglect rotational motions. With this definition, a car or even a planet can be considered a particle).

• It moves along a straight line. Its position is measured from some reference point.

Engineering Computation: An Introduction Using MATLAB and Excel

x

Page 4: Chapter 9 Numerical Integration Flow Charts, Loop Structures Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Linear Motion

• As the particle moves a distance Δx during a time period Δt, we say that the average rate of change of the position is Δx /Δt

• The velocity, the instantaneous rate of change, is found by taking the limit as Δt approaches zero:

Engineering Computation: An Introduction Using MATLAB and Excel

xΔx

Page 5: Chapter 9 Numerical Integration Flow Charts, Loop Structures Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Linear Motion

• We say that the velocity is the derivative of position with respect to time

• Similarly, the acceleration of the particle is the instantaneous rate of change of velocity, or acceleration is the derivative of velocity with respect to time:

Engineering Computation: An Introduction Using MATLAB and Excel

Page 6: Chapter 9 Numerical Integration Flow Charts, Loop Structures Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Linear Motion

• Now let’s work the other way: if we know that our speed over a period of time, can we determine how far we have gone?

• Start with the equation for velocity:

• This can be rewritten as:

Engineering Computation: An Introduction Using MATLAB and Excel

Page 7: Chapter 9 Numerical Integration Flow Charts, Loop Structures Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Linear Motion

• So over a very small period of time dt, the change of position dx will be the velocity times dt

• To get the change of position over a larger time interval, we sum (integrate) v times dt for all of the small time intervals:

Engineering Computation: An Introduction Using MATLAB and Excel

Page 8: Chapter 9 Numerical Integration Flow Charts, Loop Structures Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Graphical Interpretations

• Consider position x plotted vs. time t• The change in x divided by the change in t is the

average rate of change over that time interval:

Engineering Computation: An Introduction Using MATLAB and Excel

Δt

Δx

Page 9: Chapter 9 Numerical Integration Flow Charts, Loop Structures Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Graphical Interpretations

• As the interval time becomes infinitesimally small, the rate of change becomes the slope of the curve at a specific point in time

Engineering Computation: An Introduction Using MATLAB and Excel

t

Slope = derivative of x with respect to t

Page 10: Chapter 9 Numerical Integration Flow Charts, Loop Structures Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Graphical Interpretations

• Now consider a graph of velocity vs time• The change in position over a small time interval

dt is v times dt

Engineering Computation: An Introduction Using MATLAB and Excel

dt

v

Page 11: Chapter 9 Numerical Integration Flow Charts, Loop Structures Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Graphical Interpretations

• The change in position is the sum of these small areas – the integral of velocity over the time interval

Engineering Computation: An Introduction Using MATLAB and Excel

t1 t2

Page 12: Chapter 9 Numerical Integration Flow Charts, Loop Structures Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Graphical Interpretations

• The derivative of a function is the slope of the curve of that function at a particular point

• The integral of a function is the area under the curve of that function for a given interval

Engineering Computation: An Introduction Using MATLAB and Excel

Page 13: Chapter 9 Numerical Integration Flow Charts, Loop Structures Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Derivatives of Polynomials

• In calculus classes, you have learned (or will learn) how to differentiate many types of functions

• Polynomials are simplest to differentiate: for each term, reduce the exponent of the variable by one, and modify the term by the original exponent

• Example:

Engineering Computation: An Introduction Using MATLAB and Excel

Page 14: Chapter 9 Numerical Integration Flow Charts, Loop Structures Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Integrals of Polynomials

• To integrate a polynomial, reverse the process: for each term, add one to the exponent of the variable and divide the term by the new exponent

Note the constant term C that must be added. This term will depend on a boundary condition

Engineering Computation: An Introduction Using MATLAB and Excel

Page 15: Chapter 9 Numerical Integration Flow Charts, Loop Structures Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Definite Integrals

• The previous integral, with no limits given, is called an indefinite integral, a general solution

• When upper and lower limits are defined, this is classed a definite integral

• To evaluate a definite integral, substitute the upper and lower limits into the general solution and subtract the value at the lower limit from that of the upper limit

Engineering Computation: An Introduction Using MATLAB and Excel

Page 16: Chapter 9 Numerical Integration Flow Charts, Loop Structures Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Definite Integrals

• Example:

• Note that the constant C was ignored, its value at the lower limit is the same as at the upper limit, and so is cancelled in the subtraction

Engineering Computation: An Introduction Using MATLAB and Excel

Page 17: Chapter 9 Numerical Integration Flow Charts, Loop Structures Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Numerical Integration

• We can get an approximate value of a definite integral of any function with a numerical approach

• The key is to remember that the value of the integral is simply the area under the function’s curve

Engineering Computation: An Introduction Using MATLAB and Excel

Page 18: Chapter 9 Numerical Integration Flow Charts, Loop Structures Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Numerical Integration

• Here is the area under the curve for our example, The total area is 16 (units depend on the units of x and y)

Engineering Computation: An Introduction Using MATLAB and Excel

Page 19: Chapter 9 Numerical Integration Flow Charts, Loop Structures Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Numerical Integration

• Consider the two values of x shown here. • To find the area under the curve between these

two points, we will approximate this portion of the curve with a straight line segment

Engineering Computation: An Introduction Using MATLAB and Excel

Page 20: Chapter 9 Numerical Integration Flow Charts, Loop Structures Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Numerical Integration

• A trapezoidal area is formed:

Engineering Computation: An Introduction Using MATLAB and Excel

Page 21: Chapter 9 Numerical Integration Flow Charts, Loop Structures Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Numerical Integration Example

• We will use four intervals of x, each one unit wide• Values of y at the interval endpoints:

Engineering Computation: An Introduction Using MATLAB and Excel

y = -3

y = 24

y = 9

y = 0y = 0

Page 22: Chapter 9 Numerical Integration Flow Charts, Loop Structures Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Numerical Integration Example

Engineering Computation: An Introduction Using MATLAB and Excel

• Areas:

• Sum = 18

A = -1.5 A = -1.5

A = 16.5

A = 4.5

Page 23: Chapter 9 Numerical Integration Flow Charts, Loop Structures Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Numerical Integration Example

Engineering Computation: An Introduction Using MATLAB and Excel

• Notice that our trapezoids over estimate the positive area and under estimate the negative areas

A = -1.5 A = -1.5

A = 16.5

A = 4.5

Page 24: Chapter 9 Numerical Integration Flow Charts, Loop Structures Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Numerical Integration Example

Engineering Computation: An Introduction Using MATLAB and Excel

• Using more intervals improves the accuracy:

• Sum = 16.5

A = -1.3125

A = -0.5625

A = 6.1875

A = 0.9375

A = 3.1875

A = 9.9375

A = -1.3125

A = -0.5625

Page 25: Chapter 9 Numerical Integration Flow Charts, Loop Structures Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Numerical Integration Example

Engineering Computation: An Introduction Using MATLAB and Excel

• How do we know when we have used enough intervals? (Assuming that we don’t know the exact answer, which is probably why we are using a numerical solution)

• Try more intervals until the solution converges to a value

• This makes a MATLAB solution a good choice – we can change the number of intervals easily