Lecture10a

Lecture10a - 0306-381 Applied Programming • Numerical...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 0306-381 Applied Programming • Numerical Integration • Least Squares Curve Fitting Integral Area under a curve • Integral of f(x) on x Î [a,b] • a£x£b òa f (x )dx b Figure used with permission from support materials for Applied Numerical Methods for Engineers and Scientists, S. S. Rao, Prentice Hall, 2002. 2 Graphical Integration Area under a curve • Number of grid squares under plotted function • Approximate area Figure used with permission from support materials for Applied Numerical Methods for Engineers and Scientists, S. S. Rao, Prentice Hall, 2002. 3 Numerical Integration Area under a curve • Approximate function – Constant – Linear – Quadratic • Approximate area Figures used with permission from support materials for Applied Numerical Methods for Engineers and Scientists, S. S. Rao, Prentice Hall, 2002. 4 Newton-Cotes Formulas • Rectangular rule Piecewise Constant • Trapezoidal Rule Piecewise Linear Figure used with permission from support materials for Applied Numerical Methods for Engineers and Scientists, S. S. Rao, Prentice Hall, 2002. 5 Rectangular Rule: Endpoints • Function value at left endpoint òa f (x )dx » h × å fi = h × å f (a + i × h ) i =0 i =0 b n -1 n -1 • Function value at right endpoint òa f (x )dx » h × å fi+1 = h × å fi i =0 i =1 b n -1 n = h × å f (a + i × h ) i =1 n Figure used with permission from support materials for Applied Numerical Methods for Engineers and Scientists, S. S. Rao, Prentice Hall, 2002. 6 Rectangular Rule: Average • Average function value at endpoints òa f (x )dx » h × å i =0 b n -1 n -1 ù f i + f i +1 h é = × ê f (a ) + 2 × å f (a + i × h ) + f (b )ú 2 2ê ú i =1 ë û Figure used with permission from support materials for Applied Numerical Methods for Engineers and Scientists, S. S. Rao, Prentice Hall, 2002. 7 Trapezoidal 2-point Formula Approximation: straight line through function endpoints ò b a f (b ) - f (a )ù é f (x )dx » (b - a ) × ê f (a) + ú 2 ë û b-a » × [ f (a ) + f (b )] 2 Figure used with permission from support materials for Applied Numerical Methods for Engineers and Scientists, S. S. Rao, Prentice Hall, 2002. 8 Trapezoidal Rule • Divide interval – n equal subintervals – Length: h = xi+1 - xi • Subinterval approximation – Straight line – Contains endpoints òa f (x )dx » h × å i =0 b n -1 n -1 ù f i + f i +1 h é = × ê f (a ) + 2 × å f (a + i × h ) + f (b )ú 2 2ê ú i =1 ë û 9 Figure used with permission from support materials for Applied Numerical Methods for Engineers and Scientists, S. S. Rao, Prentice Hall, 2002. Trapezoidal Rule Pseudocode h ¬ (b - a) / n Sum ¬ 0 loop on I from 1 to (n - 1) Sum ¬ Sum + f(a + h*I) Integral ¬ .5 * h * (f(a) + f(b) + (2 * Sum)) òa f (x )dx » h × å i =0 b n -1 n -1 ù f i + f i +1 h é = × ê f (a ) + 2 × å f (a + i × h ) + f (b )ú 2 2ê ú i =1 ë û Figure used with permission from support materials for Applied Numerical Methods for Engineers and Scientists, S. S. Rao, Prentice Hall, 2002. 10 Simpson’s 3-point Formula Approximation: quadratic • Function at endpoints • Function at midpoint (b - a ) × é f (a ) + 4 × f æ a + b ö + f (b )ù ç ÷ ú òa f (x )dx » 6 ê è2ø ë û b Figure used with permission from support materials for Applied Numerical Methods for Engineers and Scientists, S. S. Rao, Prentice Hall, 2002. 11 Simpson’s Rule Accuracy • More accurate than Trapezoidal Rule • Accurate up to third degree polynomials (b - a ) × é f (a ) + 4 × f æ a + b ö + f (b )ù ç ÷ ê ú òa f (x )dx » b 6 ë è2ø û Figures used with permission from support materials for Applied Numerical Methods for Engineers and Scientists, S. S. Rao, Prentice Hall, 2002. 12 Simpson’s Rule • Divide interval – n equal subintervals – Length: h = xi+1 - xi fi fi+½ • Subinterval approximation – Quadratic – Contains endpoints and midpoint xi 2 xi+½ 2 xi+1 òa b h n-1 f (x )dx » × å f i + 4 × f i + 1 + f i +1 2 6 i =0 n -1 n -1 ù hé hö æ » × ê f (a ) + 4 × å f ç a + i × h + ÷ + 2 × å f (a + i × h ) + f (b )ú 6ê 2ø ú i =0 è i =1 ë û Figure used with permission from support materials for Applied Numerical Methods for Engineers and Scientists, S. S. Rao, Prentice Hall, 2002. 13 Simpson’s Rule Pseudocode h ¬ (b - a) / n hHalf ¬ .5 * h Sum1 ¬ 0 Sum2 ¬ 0 loop on I from 0 to (n - 1) Sum1 ¬ Sum1 + f(a + h*I + hHalf) loop on I from 1 to (n - 1) Sum2 ¬ Sum2 +f(a + h*I) Integral ¬ (h / 6) * (f(a) + f(b) + (4 * Sum1) + (2 * Sum2)) òa b n -1 n -1 ù hé hö æ f (x )dx » × ê f (a ) + 4 × å f ç a + i × h + ÷ + 2 × å f (a + i × h ) + f (b )ú 6ê 2ø ú i =0 è i =1 ë û 14 Figure used with permission from support materials for Applied Numerical Methods for Engineers and Scientists, S. S. Rao, Prentice Hall, 2002. ...
View Full Document

Ask a homework question - tutors are online