BRENT’S METHOD Applied Numerical Methods with MATLAB fo
6.4.1 Inverse Quadratic Interpolation
Inverse quadratic interpolation is similar in spirit to the secant method. As in Fig. 6.8a, the secant method is based on computing a straight line that goes through two guesses. The intersection of this straight line with the x axis represents the new root estimate. For this reason, it is sometimes referred to as a linear interpolation method. Now suppose that we had three points. In that case, we could determine a quadratic function of x that goes through the three points Fig. 6.8 b. Just as with the linear secant method, the intersection of this parabola with the x axis would represent the new root esti- mate. And as illustrated in Fig. 6.8b, using a curve rather than a straight line often yields a better estimate. Although this would seem to represent a great improvement, the approach has a fun- damental flaw: it is possible that the parabola might not intersect the x axis Such would be the case when the resulting parabola had complex roots. This is illustrated by the parabola, y ⫽ fx, in Fig. 6.9. The difficulty can be rectified by employing inverse quadratic interpolation. That is, rather than using a parabola in x, we can fit the points with a parabola in y. This amounts to reversing the axes and creating a “sideways” parabola [the curve, x ⫽ fy, in Fig. 6.9]. If the three points are designated as x i –2 , y i –2 , x i –1 , y i –1 , and x i , y i , a quadratic function of y that passes through the points can be generated as gy = y − y i −1 y − y i y i −2 − y i −1 y i −2 − y i x i −2 + y − y i −2 y − y i y i −1 − y i −2 y i −1 − y i x i −1 + y − y i −2 y − y i −1 y i − y i −2 y i − y i −1 x i 6.10 f x x a b f x x FIGURE 6.8 Comparison of a the secant method and b inverse quadratic interpolation. Note that the approach in b is called “inverse” because the quadratic function is written in y rather than in x. 6.4 BRENT’S METHODS 165 As we will learn in Sec. 18.2, this form is called a Lagrange polynomial. The root, x i⫹ 1, cor- responds to y ⫽ 0, which when substituted into Eq. 6.10 yields x i +1 = y i −1 y i y i −2 − y i −1 y i −2 − y i x i −2 + y i −2 y i y i −1 − y i −2 y i −1 − y i x i −1 + y i −2 y i −1 y i − y i −2 y i − y i −1 x i 6.11 As shown in Fig. 6.9, such a “sideways” parabola always intersects the x axis. EXAMPLE 6.6 Inverse Quadratic Interpolation Problem Statement. Develop quadratic equations in both x and y for the data points depicted in Fig. 6.9: 1, 2, 2, 1, and 4, 5. For the first, y ⫽ fx, employ the quadratic formula to illustrate that the roots are complex. For the latter, x ⫽ gy, use inverse qua- dratic interpolation Eq. 6.11 to determine the root estimate. Solution. By reversing the x’s and y’s, Eq. 6.10 can be used to generate a quadratic in x as f x = x − 2x − 4 1 − 21 − 4 2 + x − 1x − 4 2 − 12 − 4 1 + x − 1x − 2 4 − 14 − 2 5 or collecting terms f x = x 2 − 4x + 5 4 2 6 4 2 y x ⫽ fy y ⫽ fx x Root FIGURE 6.9 Two parabolas fit to three points. The parabola written as a function of x, y ⫽ fx, has complex roots and hence does not intersect the x axis. In contrast, if the variables are reversed, and the parabola developed as x ⫽ fy, the function does intersect the x axis. This equation was used to generate the parabola, y ⫽ fx, in Fig. 6.9. The quadratic for- mula can be used to determine that the roots for this case are complex, x = 4 ± −4 2 − 415 2 = 2 ± i Equation 6.10 can be used to generate the quadratic in y as gy = y − 1y − 5 2 − 12 − 5 1 + y − 2y − 5 1 − 21 − 5 2 + y − 2y − 1 5 − 25 − 1 4 or collecting terms: gy = 0.5x 2 − 2.5x + 4 Finally, Eq. 6.11 can be used to determine the root as x i +1 = −1−5 2 − 12 − 5 1 + −2−5 1 − 21 − 5 2 + −2−1 5 − 25 − 1 4 = 4 Before proceeding to Brent’s algorithm, we need to mention one more case where inverse quadratic interpolation does not work. If the three y values are not distinct i.e., y i –2 ⫽ y i –1 or y i –1 ⫽ y i , an inverse quadratic function does not exist. So this is where the secant method comes into play. If we arrive at a situation where the y values are not distinct, we can always revert to the less efficient secant method to generate a root using two of the points. If y i⫺2 ⫽ y i⫺1 , we use the secant method with x i –1 and x i . If y i –1 ⫽ y i , we use x i –2 and x i –1 .6.4.2 Brent’s Method Algorithm
The general idea behind the Brent’s root-finding method is whenever possible to use one of the quick open methods. In the event that these generate an unacceptable result i.e., a root estimate that falls outside the bracket, the algorithm reverts to the more conservative bisection method. Although bisection may be slower, it generates an estimate guaranteed to fall within the bracket. This process is then repeated until the root is located to within an acceptable tolerance. As might be expected, bisection typically dominates at first but as the root is approached, the technique shifts to the faster open methods. Figure 6.10 presents a function based on a MATLAB M-file developed by Cleve Moler 2004. It represents a stripped down version of the fzero function which is the pro- fessional root-location function employed in MATLAB. For that reason, we call the simplified version: fzerosimp. Note that it requires another function f that holds the equation for which the root is being evaluated. The fzerosimp function is passed two initial guesses that must bracket the root. Then, the three variables defining the search interval a,b,c are initialized, and f is eval- uated at the endpoints. A main loop is then implemented. If necessary, the three points are rearranged to satisfy the conditions required for the algorithm to work effectively. At this point, if the stopping 6.4 BRENT’S METHODS 167 function b = fzerosimpxl,xu a = xl; b = xu; fa = fa; fb = fb; c = a; fc = fa; d = b - c; e = d; while 1 if fb == 0, break, end if signfa == signfb If needed, rearrange points a = c; fa = fc; d = b - c; e = d; end if absfa absfb c = b; b = a; a = c; fc = fb; fb = fa; fa = fc; end m = 0.5a - b; Termination test and possible exit tol = 2 eps maxabsb, 1; if absm = tol | fb == 0. break end Choose open methods or bisection if abse = tol absfc absfb s = fbfc; if a == c Secant method p = 2ms; q = 1 - s; else Inverse quadratic interpolation q = fcfa; r = fbfa; p = s 2mq q - r - b - cr - 1; q = q - 1r - 1s - 1; end if p 0, q = -q; else p = -p; end; if 2p 3mq - abstolq p abs0.5eq e = d; d = pq; else d = m; e = m; end else Bisection d = m; e = m; end c = b; fc = fb; if absd tol, b=b+d; else b=b-signb-atol; end fb = fb; end FIGURE 6.10 Function for Brent’s root-finding algorithm based on a MATLAB M-file developed by Cleve Moler 2005. criteria are met, the loop is terminated. Otherwise, a decision structure chooses among the three methods and checks whether the outcome is acceptable. A final section then evaluates f at the new point and the loop is repeated. Once the stopping criteria are met, the loop terminates and the final root estimate is returned.6.5 MATLAB FUNCTION:
fzero The fzero function is designed to find the real root of a single equation. A simple repre- sentation of its syntax is fzerofunction,x0 where function is the name of the function being evaluated, and x0 is the initial guess. Note that two guesses that bracket the root can be passed as a vector: fzerofunction,[x0 x1] where x0 and x1 are guesses that bracket a sign change. Here is a simple MATLAB session that solves for the root of a simple quadratic: x 2 − 9. Clearly two roots exist at −3 and 3. To find the negative root: x = fzerox x2-9,-4 x = -3 If we want to find the positive root, use a guess that is near it: x = fzerox x2-9,4 x = 3 If we put in an initial guess of zero, it finds the negative root: x = fzerox x2-9,0 x = -3 If we wanted to ensure that we found the positive root, we could enter two guesses as in x = fzerox x2-9,[0 4] x = 3 Also, if a sign change does not occur between the two guesses, an error message is displayed x = fzerox x2-9,[-4 4] ??? Error using == fzero The function values at the interval endpoints must ... differ in sign. 6.5 MATLAB FUNCTION: fzero 169Parts
» Applied Numerical Methods with MATLAB fo
» Motivation 1 1.2 Part Organization 2 Overview 123 2.2 Part Organization 124
» Overview 205 3.2 Part Organization 207 Overview 321 4.2 Part Organization 323
» Overview 459 5.2 Part Organization 460 Applied Numerical Methods with MATLAB fo
» New Chapters. Overview 547 6.2 Part Organization 551
» New Content. Overview 547 6.2 Part Organization 551
» New Homework Problems. Overview 547 6.2 Part Organization 551
» Numerical methods greatly expand the
» Numerical methods allow you to use
» PART ORGANIZATION Applied Numerical Methods with MATLAB fo
» CONSERVATION LAWS IN ENGINEERING AND SCIENCE
» NUMERICAL METHODS COVERED IN THIS BOOK
» CASE STUDY IT’S A REAL DRAG CASE STUDY continued
» CASE STUDY continued Applied Numerical Methods with MATLAB fo
» Use calculus to verify that Eq. 1.9 is a solution of
» Use calculus to solve Eq. 1 for the case where the ini-
» The following information is available for a bank account:
» Rather than the nonlinear relationship of Eq. 1.7, you
» For the free-falling bungee jumper with linear drag
» For the second-order drag model Eq. 1.8, compute the
» The amount of a uniformly distributed radioactive con-
» A storage tank Fig. P contains a liquid at depth y
» For the same storage tank described in Prob. 1.9, sup-
» Apply the conservation of volume see Prob. 1.9 to sim-
» THE MATLAB ENVIRONMENT ASSIGNMENT
» MATHEMATICAL OPERATIONS Applied Numerical Methods with MATLAB fo
» GRAPHICS Applied Numerical Methods with MATLAB fo
» OTHER RESOURCES Applied Numerical Methods with MATLAB fo
» CASE STUDY EXPLORATORY DATA ANALYSIS CASE STUDY continued
» Manning’s equation can be used to compute the veloc-
» It is general practice in engineering and science that
» You contact the jumpers used to generate the data in
» Figure Pa shows a uniform beam subject to a lin-
» M-FILES Applied Numerical Methods with MATLAB fo
» INPUT-OUTPUT Applied Numerical Methods with MATLAB fo
» STRUCTURED PROGRAMMING Applied Numerical Methods with MATLAB fo
» NESTING AND INDENTATION Applied Numerical Methods with MATLAB fo
» PASSING FUNCTIONS TO M-FILES
» CASE STUDY BUNGEE JUMPER VELOCITY CASE STUDY continued
» Economic formulas are available to compute annual
» Two distances are required to specify the location of a
» Develop an M-file to determine polar coordinates as
» Develop an M-file function that is passed a numeric
» Manning’s equation can be used to compute the velocity
» The volume V of liquid in a hollow horizontal cylinder of
» Develop a vectorized version of the following code:
» Based on Example 3.6, develop a script to produce an
» ERRORS Applied Numerical Methods with MATLAB fo
» Digital computers have magnitude and precision limits on their ability to represent
» Arithmetic Manipulations of Computer Numbers
» TRUNCATION ERRORS Applied Numerical Methods with MATLAB fo
» TOTAL NUMERICAL ERROR Applied Numerical Methods with MATLAB fo
» BLUNDERS, MODEL ERRORS, AND DATA UNCERTAINTY
» a Applied Numerical Methods with MATLAB fo
» OVERVIEW Applied Numerical Methods with MATLAB fo
» ROOTS IN ENGINEERING AND SCIENCE
» GRAPHICAL METHODS Applied Numerical Methods with MATLAB fo
» BRACKETING METHODS AND INITIAL GUESSES
» BISECTION Applied Numerical Methods with MATLAB fo
» FALSE POSITION Applied Numerical Methods with MATLAB fo
» CASE STUDY GREENHOUSE GASES AND RAINWATER CASE STUDY continued
» Locate the first nontrivial root of sinx = x
» Determine the positive real root of lnx
» A total charge Q is uniformly distributed around a ring-
» For fluid flow in pipes, friction is described by a di-
» Perform the same computation as in Prob. 5.22, but for
» SIMPLE FIXED-POINT ITERATION Applied Numerical Methods with MATLAB fo
» NEWTON-RAPHSON Applied Numerical Methods with MATLAB fo
» SECANT METHODS Applied Numerical Methods with MATLAB fo
» BRENT’S METHOD Applied Numerical Methods with MATLAB fo
» MATLAB FUNCTION: Applied Numerical Methods with MATLAB fo
» POLYNOMIALS Applied Numerical Methods with MATLAB fo
» CASE STUDY PIPE FRICTION CASE STUDY continued
» CASE STUDY continued CASE STUDY continued
» Use a fixed-point iteration and b the Newton-
» Use a the Newton-Raphson method and b the modi-
» Develop an M-file for the secant method. Along with
» Develop an M-file for the modified secant method.
» Differentiate Eq. E6.4.1 to get Eq. E6.4.2. a
» Perform the identical MATLAB operations as those
» In control systems analysis, transfer functions are
» Use the Newton-Raphson method to find the root of Given a
» INTRODUCTION AND BACKGROUND Applied Numerical Methods with MATLAB fo
» MULTIDIMENSIONAL OPTIMIZATION Applied Numerical Methods with MATLAB fo
» CASE STUDY EQUILIBRIUM AND MINIMUM POTENTIAL ENERGY
» Employ the following methods to find the minimum of
» Consider the following function:
» Develop a single script to a generate contour and
» The head of a groundwater aquifer is described in
» Recent interest in competitive and recreational cycling
» The normal distribution is a bell-shaped curve defined by
» Use the Applied Numerical Methods with MATLAB fo
» Given the following function:
» The specific growth rate of a yeast that produces an
» A compound A will be converted into B in a stirred
» Develop an M-file to locate a minimum with the
» Develop an M-file to implement parabolic interpola-
» Pressure measurements are taken at certain points
» The trajectory of a ball can be computed with
» The deflection of a uniform beam subject to a linearly
» The torque transmitted to an induction motor is a func-
» The length of the longest ladder that can negotiate
» MATRIX ALGEBRA OVERVIEW Applied Numerical Methods with MATLAB fo
» SOLVING LINEAR ALGEBRAIC EQUATIONS WITH MATLAB
» CASE STUDY CURRENTS AND VOLTAGES IN CIRCUITS CASE STUDY continued
» Five reactors linked by pipes are shown in Fig. P.
» SOLVING SMALL NUMBERS OF EQUATIONS
» MATLAB M-file: Operation Counting
» PIVOTING Applied Numerical Methods with MATLAB fo
» TRIDIAGONAL SYSTEMS Applied Numerical Methods with MATLAB fo
» CASE STUDY MODEL OF A HEATED ROD CASE STUDY continued
» Given the system of equations
» Given the equations Applied Numerical Methods with MATLAB fo
» An electrical engineer supervises the production of three
» Develop an M-file function based on Fig. 9.5 to im-
» GAUSS ELIMINATION AS LU FACTORIZATION
» CHOLESKY FACTORIZATION Applied Numerical Methods with MATLAB fo
» MATLAB LEFT DIVISION Applied Numerical Methods with MATLAB fo
» Use Cholesky factorization to determine [U] so that THE MATRIX INVERSE
» Norms and Condition Number in MATLAB
» CASE STUDY INDOOR AIR POLLUTION CASE STUDY continued
» Determine the matrix inverse for the system described
» Determine A Applied Numerical Methods with MATLAB fo
» Determine the Frobenius and row-sum norms for the
» Use MATLAB to determine the spectral condition num-
» Besides the Hilbert matrix, there are other matrices
» Use MATLAB to determine the spectral condition
» Repeat Prob. 11.10, but for the case of a six-
» The Lower Colorado River consists of a series of four a
» A chemical constituent flows between three reactors a
» LINEAR SYSTEMS: GAUSS-SEIDEL Applied Numerical Methods with MATLAB fo
» NONLINEAR SYSTEMS Applied Numerical Methods with MATLAB fo
» CASE STUDY CHEMICAL REACTIONS
» Use the Gauss-Seidel method to solve the following
» Repeat Prob. 12.3 but use Jacobi iteration.
» The following system of equations is designed to de-
» Solve the following system using three iterations with a
» MATHEMATICAL BACKGROUND Applied Numerical Methods with MATLAB fo
» PHYSICAL BACKGROUND Applied Numerical Methods with MATLAB fo
» THE POWER METHOD Applied Numerical Methods with MATLAB fo
» CASE STUDY EIGENVALUES AND EARTHQUAKES CASE STUDY continued
» Repeat Example but for three masses with the m’s =
» Use the power method to determine the highest eigen-
» Use the power method to determine the lowest eigen-
» Derive the set of differential equations for a three
» Consider the mass-spring system in Fig. P. The fre-
» STATISTICS REVIEW Applied Numerical Methods with MATLAB fo
» RANDOM NUMBERS AND SIMULATION
» LINEAR LEAST-SQUARES REGRESSION Applied Numerical Methods with MATLAB fo
» LINEARIZATION OF NONLINEAR RELATIONSHIPS
» COMPUTER APPLICATIONS Applied Numerical Methods with MATLAB fo
» CASE STUDY continued CASE STUDY continued CASE STUDY continued
» Using the same approach as was employed to derive
» Beyond the examples in Fig. 14.13, there are other
» The concentration of E. coli bacteria in a swimming
» Rather than using the base-e exponential model
» Determine an equation to predict metabolism rate as a
» On average, the surface area A of human beings is
» 2.12 2.15 2.20 2.22 2.23 2.26 2.30 Applied Numerical Methods with MATLAB fo
» An investigator has reported the data tabulated below
» Develop an M-file function to compute descriptive
» Modify the Applied Numerical Methods with MATLAB fo
» Develop an M-file function to fit a power model.
» Below are data taken from a batch reactor of bacterial
» A transportation engineering study was conducted to
» In water-resources engineering, the sizing of reser-
» Perform the same computation as in Example 14.3,
» POLYNOMIAL REGRESSION Applied Numerical Methods with MATLAB fo
» MULTIPLE LINEAR REGRESSION Applied Numerical Methods with MATLAB fo
» GENERAL LINEAR LEAST SQUARES
» QR FACTORIZATION AND THE BACKSLASH OPERATOR
» NONLINEAR REGRESSION Applied Numerical Methods with MATLAB fo
» CASE STUDY FITTING EXPERIMENTAL DATA CASE STUDY continued
» Fit a parabola to the data from Table 14.1. Determine
» Fit a cubic polynomial to the following data:
» Use multiple linear regression to derive a predictive
» As compared with the models from Probs. 15.5 and
» Use multiple linear regression to fit
» The following data were collected for the steady flow
» In Prob. 14.8 we used transformations to linearize
» Enzymatic reactions are used extensively to charac-
» The following data represent the bacterial growth in a
» Dynamic viscosity of water μ10
» Use the following set of pressure-volume data to find
» Environmental scientists and engineers dealing with
» It is known that the data tabulated below can be mod-
» hr Applied Numerical Methods with MATLAB fo
» CURVE FITTING WITH SINUSOIDAL FUNCTIONS
» CONTINUOUS FOURIER SERIES Applied Numerical Methods with MATLAB fo
» FOURIER INTEGRAL AND TRANSFORM
» DISCRETE FOURIER TRANSFORM DFT
» THE POWER SPECTRUM Applied Numerical Methods with MATLAB fo
» CASE STUDY SUNSPOTS Applied Numerical Methods with MATLAB fo
» The pH in a reactor varies sinusoidally over the course
» The solar radiation for Tucson, Arizona, has been tab-
» Use MATLAB to generate 64 points from the function
» INTRODUCTION TO INTERPOLATION Applied Numerical Methods with MATLAB fo
» NEWTON INTERPOLATING POLYNOMIAL Applied Numerical Methods with MATLAB fo
» LAGRANGE INTERPOLATING POLYNOMIAL Applied Numerical Methods with MATLAB fo
» INVERSE INTERPOLATION Applied Numerical Methods with MATLAB fo
» EXTRAPOLATION AND OSCILLATIONS Applied Numerical Methods with MATLAB fo
» Given the data Applied Numerical Methods with MATLAB fo
» Use the portion of the given steam table for super-
» The following data for the density of nitrogen gas ver-
» Ohm’s law states that the voltage drop V across an
» The acceleration due to gravity at an altitude y above
» INTRODUCTION TO SPLINES Applied Numerical Methods with MATLAB fo
» LINEAR SPLINES Applied Numerical Methods with MATLAB fo
» CUBIC SPLINES Applied Numerical Methods with MATLAB fo
» PIECEWISE INTERPOLATION IN MATLAB
» MULTIDIMENSIONAL INTERPOLATION Applied Numerical Methods with MATLAB fo
» CASE STUDY HEAT TRANSFER CASE STUDY continued
» A reactor is thermally stratified as in the following
» The following is the built-in
» Develop a plot of a cubic spline fit of the following
» The following data define the sea-level concentra- a
» NEWTON-COTES FORMULAS Applied Numerical Methods with MATLAB fo
» THE TRAPEZOIDAL RULE Applied Numerical Methods with MATLAB fo
» SIMPSON’S RULES Applied Numerical Methods with MATLAB fo
» HIGHER-ORDER NEWTON-COTES FORMULAS Applied Numerical Methods with MATLAB fo
» INTEGRATION WITH UNEQUAL SEGMENTS
» OPEN METHODS MULTIPLE INTEGRALS
» CASE STUDY COMPUTING WORK WITH NUMERICAL INTEGRATION CASE STUDY continued CASE STUDY continued
» Derive Eq. 19.4 by integrating Eq. 19.3. Evaluate the following integral:
» INTRODUCTION Applied Numerical Methods with MATLAB fo
» ROMBERG INTEGRATION Applied Numerical Methods with MATLAB fo
» GAUSS QUADRATURE Applied Numerical Methods with MATLAB fo
» MATLAB Functions: If the error is larger than the tolerance,
» CASE STUDY ROOT-MEAN-SQUARE CURRENT CASE STUDY continued
» Evaluate the following integral a analytically,
» Evaluate the following integral with a Romberg inte-
» Evaluate the double integral Compute work as described in Sec. 19.9, but use the
» Suppose that the current through a resistor is de-
» km 1100 1500 2450 3400 3630 4500 km 5380 6060 6280 6380 Applied Numerical Methods with MATLAB fo
» HIGH-ACCURACY DIFFERENTIATION FORMULAS Applied Numerical Methods with MATLAB fo
» RICHARDSON EXTRAPOLATION Applied Numerical Methods with MATLAB fo
» DERIVATIVES OF UNEQUALLY SPACED DATA
» DERIVATIVES AND INTEGRALS FOR DATA WITH ERRORS
» PARTIAL DERIVATIVES Applied Numerical Methods with MATLAB fo
» NUMERICAL DIFFERENTIATION WITH MATLAB
» CASE STUDY VISUALIZING FIELDS CASE STUDY continued
» Develop an M-file to obtain first-derivative estimates
» Develop an M-file function that computes first and
» A jet fighter’s position on an aircraft carrier’s runway
» Use the following data to find the velocity and accel-
» A plane is being tracked by radar, and data are taken
» Use regression to estimate the acceleration at each
» The normal distribution is defined as
» The following data were generated from the normal Use the
» The objective of this problem is to compare second-
» The pressure gradient for laminar flow through a con-
» The following data for the specific heat of benzene
» The specific heat at constant pressure c
» OVERVIEW IMPROVEMENTS OF EULER’S METHOD
» RUNGE-KUTTA METHODS Applied Numerical Methods with MATLAB fo
» SYSTEMS OF EQUATIONS Applied Numerical Methods with MATLAB fo
» CASE STUDY PREDATOR-PREY MODELS AND CHAOS
» Develop an M-file to solve a single ODE with Heun’s
» Develop an M-file to solve a single ODE with the
» Develop an M-file to solve a system of ODEs with
» Isle Royale National Park is a 210-square-mile archi-
» The motion of a damped spring-mass system
» Perform the same simulations as in Section 22.6 for ADAPTIVE RUNGE-KUTTA METHODS
» MULTISTEP METHODS Applied Numerical Methods with MATLAB fo
» STIFFNESS Applied Numerical Methods with MATLAB fo
» MATLAB APPLICATION: BUNGEE JUMPER WITH CORD
» CASE STUDY PLINY’S INTERMITTENT FOUNTAIN CASE STUDY continued
» Given Applied Numerical Methods with MATLAB fo
» THE SHOOTING METHOD Applied Numerical Methods with MATLAB fo
» FINITE-DIFFERENCE METHODS Applied Numerical Methods with MATLAB fo
» A cable is hanging from two supports at A and B
» In Prob. 24.16, the basic differential equation of the
Show more