1 / 24

Numerical Methods

Numerical Methods. Lecture 3 - Numerical Integration Dr Andy Phillips School of Electrical and Electronic Engineering University of Nottingham. Today’s Topics. Numerical Integration Basic theory Left Hand rule Right Hand rule Midpoint rule Trapezoidal Rule Simpson’s rule. Motivation.

tacey
Download Presentation

Numerical Methods

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Numerical Methods Lecture 3 - Numerical Integration Dr Andy Phillips School of Electrical and Electronic Engineering University of Nottingham

  2. Today’s Topics • Numerical Integration • Basic theory • Left Hand rule • Right Hand rule • Midpoint rule • Trapezoidal Rule • Simpson’s rule

  3. Motivation • While mathematically integration is “finding the area under a curve” there are many, many applications of integration within engineering where we are actually finding a physical quantity that interests us • Integrate… • …current over time to get charge • …power over time to get energy • …velocity over time to get distance • etc.

  4. Numerical Integration f(x) I x x1 x2 x2 For a definite integral, represented by area I: I = f(x).dx   x1

  5. Why numerical integration? • For DEFINITE integrals • Simple integrals we can solve by hand • For more complex ones (e.g. below) we can use computer systems like Maple or Mathcad to get an analytical solution

  6. But… • Often integrals • Are too difficult to solve analytically (by hand) • May not even have a solution that can be expressed symbolically • As a result we resort to numerical methods

  7. Methods Available • The are a number of methods available • Left Hand Rule • Right Hand Rule • Midpoint • Trapezoidal Rule • Simpson’s Rule • But fundamentally they are all the same • (especially the 1st four)

  8. How they work • The idea is to • break the integral down into a number of individual areas • sum these areas to get the total integral • The accuracy of the final result depends upon • The ‘width’ of the blocks • The ‘fit’ of the block shape we use

  9. Left hand/right hand/midpoint methods • We approximate the curve to a series of rectangles • The name of the method indicates what we consider the height of the block to be • The next slide show this graphically

  10. Comparing the methods Left Right Middle The only difference is what we consider the height of the block to be

  11. Proof (by inspection) y(x1) x1 y(xmp) A = y(x).dx   y(x0) x0 A (A is the exact area of the strip) xmp=(x0+x1)/2 xo xmp x1 • But if (x1-x0) is small, A = width * height = (x1-x0)H (approx.) • where H = y(x0) (lh) or y(x1) (rh) or y(xmp) (mp) • Note: as width (x1-x0) tends to zero all 3 methods converge

  12. The final result is the sum of the areas • We do this numerically by: • Asking the user the limits of the integral • And how many ‘blocks’ to use (hence the interval size) • We then use a loop to calculate the size of the individual areas • Which we sum for the final result

  13. However • Whilst the methods are OK, the error is often large • E.g. Left Hand Rule: Error Rectangle

  14. A better solution is a trapezoid • A better fit to a curve Error (smaller!) b a A =(a+b)h 2 Trapezoid (approx.) A h width = h (sometimes called x)

  15. Hence the trapezoidal rule A1 A2 xo x2 x1 x1 x2 A = y(x).dx + y(x).dx = A1 + A2 (approx.)     x0 x1 (A1 and A2 are trapezoid areas)

  16. Continuing… x1 x2 A = y(x).dx + y(x).dx = A1 + A2 (approx.)     x0 x1 =h[y(x1) + y(xo) ]/2 + h[y(x2) + y(x1)]/2 =h [y(x1) + y(xo) + y(x2) + y(x1)] 2 =h [y(x0) + 2y(x1) + y(x2) ] 2

  17. Over the complete range n-1 A =h [y(x0) + y(xn) ] + h  y(xi) 2 i=1 Note: this formula only works if ‘h’ is the same size over the whole range

  18. To do this computationally • We could use the formula from previous slide: • (1) Define the function y(x) • (2) ask for limits & blocks -> ‘h’ • (3) Calculate first and last heights and halve them, storing result in ‘sum’ • (4) Loop i = 1 to (n-1), adding heights to ‘sum’ • (5) Multiply ‘sum’ by ‘h’ to get answer

  19. Alternatively… • We could simply calculate the area of a strip and add it to a running total: • (1) Define the function y(x) • (2) ask for limits & blocks -> ‘h’ • (3) initialise ‘sum’ to be 0 • (4) Loop i = 1 to n calculating area of ith strip as (y(xi)-y(xi-1))h/2 and add to ‘sum’

  20. Time for a demonstration

  21. Simpson’s rule • This is a more advanced method where we use two strips and approximate the curve using a quadratic Curve f(x) q(x) = ax2 + bx + c Note: i) we MUST have an even total number of strips ii) q(x) is different for each pair of strips

  22. The theory

  23. For the whole curve

  24. Lab work • On Wednesday… • You are required to numerically determine • LH, RH & Midpoint methods • The Trapezoidal rule • Simpson’s rule (if time permits) • The actual value is 0.4134109052 • from solving the integral by hand using:

More Related