Lecture04 - 0306-381 Applied Programming Lecture Four •...

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 Lecture Four • Computer (Numerical) Solutions • Finding Real Roots Computer (Numerical) Solutions • When used? – Analytical solution not possible – Analytical solution not practical (e.g., not worth time and effort) • Issues: error – Modeling error – Discretization/truncation error – Roundoff/data error – Human error 2 Example Numerical Calculation Modulus of elasticity (E) of steal beam • Value from standard table: 30 MN/m2 • Value from calculation using formula and measurements § m = mass (0.491 kg) § l = length (0.451 m) § a = width (0.021 m) § b = thickness (0.003) § d = defelction (0.142 m) 3 3 4 mgl E= dab 4 × (0.491kg ) × (9.81m/s 2 ) × (0.451m) 3 E= (0.142m) × (0.021m) × (0.003m) 3 = 22.0MN/m 2 3 Finding Roots • Some applications, for example – Calculating volume of a gas – Determing resistance to dissipate energy at a specified rate in and RLC circuit – Calculating friction factor for air flow • Two approaches – Bracketing—simple enclosure methods – Fixed-point iteration—open methods 4 Example Problem • Function describing speed of electric motor RPM (v) = -0.02v + 0.75v + 52.2v 3 2 • Want to know voltage for 1909 rpm, given that voltage can range from 0 V to 50V 0 = -0.02v + 0.75v + 52.2v - 1909 3 2 – Want solution ' vÎ[0, 50] – Analytical solution—possible, but would have to be repeated for every rpm value of interest 5 0306-381 Applied Programming Finding Real Roots • Incremental Search Method • Bisection Method • Regula Falsi Method • Secant Method • Newton’s Method Incremental Search Method • Works when the interval contains an odd number of roots – Function value to either side of desired root must be of opposite sign – Will not distinguish between and root and a singularity – Will not work for a double root þOpposite sign to either side ý Root versus singularity ý Double Root Used with permission from support materials for Applied Numerical Methods for Engineers and Scientists, S. S. Rao, Prentice Hall, 2002. 7 Incremental Search Example f(xi) 500 0 0 -500 f(xi) -1000 5 10 15 20 25 30 35 40 -1500 -2000 x0 x1 x2 x3 . . . Used with permission from support materials for Applied Numerical Methods for Engineers and Scientists, S. S. Rao, Prentice Hall, 2002. 8 Incremental Search Algorithm Evaluate function at first point, xi. Evaluate function at xi + Dx. Yes Root found? No Yes Done Reduce Dx Does [xi, xi + Dx] interval bracket a root? No xi = xi + Dx 9 Bisection Method Finding Real Roots • Incremental Search Method FBisection Method • Regula Falsi Method • Secant Method • Newton’s Method Bisection • Works when the interval contains an odd number of roots – Each endpoint corresponds to a function value of opposite sign – Will not work for a double root Used with permission from support materials for Applied Numerical Methods for Engineers and Scientists, S. S. Rao, Prentice Hall, 2002. 11 Bisection Example Used with permission from support materials for Applied Numerical Methods for Engineers and Scientists, S. S. Rao, Prentice Hall, 2002. 12 Evaluate function at upper and lower endpoints of interval. Bisection Algorithm No Error Does interval bracket a root? Yes Calculate midpoint of interval. Evaluate function at midpoint. Yes Root found? No Use midpoint as lower endpoint. Yes Done Does upper half of interval bracket a root? No Use midpoint as upper endpoint. Adapted from S. Jay Yang, Dept. of Computer Engineering, RIT. 13 Regula Falsi Method Finding Real Roots • Incremental Search Method • Bisection Method FRegula Falsi Method • Secant Method • Newton’s Method Regula Falsi • Works when the interval contains an odd number of roots – Each endpoint corresponds to a function value of opposite sign – Will not work for a double root Used with permission from support materials for Applied Numerical Methods for Engineers and Scientists, S. S. Rao, Prentice Hall, 2002. 15 Regula Falsi Example Used with permission from support materials for Applied Numerical Methods for Engineers and Scientists, S. S. Rao, Prentice Hall, 2002. 16 Evaluate function at upper and lower endpoints of interval. Regula Falsi Algorithm No Error Does interval bracket a root? Yes Calculate x intercept of interval segment. xUpper - xLower x New = xUpper - f ( xUpper ) f ( xUpper ) - f ( xLower ) Evaluate function at x intercept. Yes Root found? No Use x intercept as lower endpoint. Yes Done Does upper half of interval bracket a root? No Use x intercept as upper endpoint. Adapted from S. Jay Yang, Dept. of Computer Engineering, RIT. 17 Regula Falsi Modified Used with permission from support materials for Applied Numerical Methods for Engineers and Scientists, S. S. Rao, Prentice Hall, 2002. 18 Secant Method Finding Real Roots • Incremental Search Method • Bisection Method • Regula Falsi Method FSecant Method • Newton’s Method Secant • Determine where chord between two interval endpoints crosses x axis. – Problematic if function has the same value at both points – Problematic if both points are very close Used with permission from support materials for Applied Numerical Methods for Engineers and Scientists, S. S. Rao, Prentice Hall, 2002. 20 Secant Algorithm Evaluate function at first two points. Calculate x intercept of interval segment. xi +1 = xi - f ( xi ) xi - xi -1 f ( xi ) - f ( xi -1 ) Evaluate function at xi+1. Root found? No i ++ Yes Done 21 Newton’s Method Finding Real Roots • Incremental Search Method • Bisection Method • Regula Falsi Method • Secant Method FNewton’s Method Newton’s Method • Newton-Raphson Method – Requires derivative of function – Converges quickly in most cases • Problem cases – x1 far away from root – f ’(xi) varies rapidly near root – f ’(xi) close to zero Used with permission from support materials for Applied Numerical Methods for Engineers and Scientists, S. S. Rao, Prentice Hall, 2002. 23 Newton’s Method Example Used with permission from support materials for Applied Numerical Methods for Engineers and Scientists, S. S. Rao, Prentice Hall, 2002. 24 Evaluate function and its derivative at initial guess. Newton’s Algorithm Determine next guess. Next = Guess - f (Guess ) f ¢(Guess ) Evaluate function at next guess. Yes Root found? No Done Evaluate derivative at next guess. Adapted from S. Jay Yang, Dept. of Computer Engineering, RIT. 25 ...
View Full Document

This note was uploaded on 04/27/2010 for the course EECC 0306-381 taught by Professor Roymelton during the Spring '10 term at RIT.

Ask a homework question - tutors are online