Numerical Methods For Civil Engineers
Numerical Methods For Civil Engineers
Lecture Notes CE 311K Daene C. McKinney Introduction to Computer Methods Department of Civil, Architectural and Environmental Engineering The University of Texas at Austin
Nonlinear Equations
Introduction
In this section we consider methods for solving nonlinear equations. Given a nonlinear function f(x), we seek a value of x for which (1)
Such a solution value for x is called a root of the equation, and a zero of the function f. An example of a nonlinear equation in one variable is
As can be seen from Figure 1, the function has roots at 0.0 and near 1.9. Graphical examination of a function is often a good way to find the neighborhood of roots.
CE311K
DCM 2/8/09
(3)
to solve for successively more accurate approximations of the root. Consider our previous example
CE311K
DCM 2/8/09
We could solve the equation for x by starting with an initial guess of x = x0 and computing x1 as
we would continue this process for several iterations until the value of xi+1 was sufficiently close to the previous value of xi. That is we would continue our iterations until the relative approximate error was less than an assigned accuracy :
CE311K
DCM 2/8/09
Thus
Table 1. Fixed point iteration method for finding the root of Iteration i Approximate root Approximate error
xi
CE311K
DCM 2/8/09
0 1 2 9 10
Figure 2. Approximate relative error for each iteration in the fixed point iteration method of finding a root of the function f (x) = e
x
x.
Bisection Method
The sign of a function f(x) changes on opposite sides of a root. Suppose the continuous real valued function f(x) has one root in the interval between x = a and x = c , or [a,c], as shown in the Figure below. The bisection method is based on the fact that when an interval [a,c] contains a root, the sign of the function at the two ends (f(a) and f(c)) are opposite each other, namely
CE311K
DCM 2/8/09
The first step in the bisection method is to bisect the interval [a,c] into two halves, namely [a,b] and [b,c], where
By checking the signs of f(a)*f(b) and f(b)*f(c), the half-interval containing the root can be identified. If f(a)*f(b) < 0, the interval [a,b] has the root, otherwise the other interval [b,c] has the root. Then the new interval containing the root is bisected again. As the procedure is repeated the interval becomes smaller and smaller. At each step, the midpoint of the interval containing the root is taken as the best approximation of the root. The iterative procedure is stopped when the half-interval size is less than a prespecified size.
CE311K 6 DCM 2/8/09
where the numerator (c-a)0 is the initial interval size. This represents the error when the root is approximated by the midpoint of the interval after the nth iteration. That is, the root could actually lie anywhere inside the interval. Therefore, if the tolerance for the error is , the number of iteration steps required is the smallest integer satisfying
which can be solved for an estimate of the number of iterations required to achieve the given tolerance. The error can be computed as
where
previous iteration. Example: Use the Bisection method to determine the drag coefficient c needed for a parachutist of mass m = 68.1 kg to have a velocity of v = 40 m/s after free-falling for time t = 10 s. Let the acceleration of gravity be g = 9.8 m/s2. Recall the equation for free-fall velocity of an object:
Figure 4. Plot of
vs c
The first step is to select two values of c where f(c) has different signs. From the Figure we see that the function changes sign between 12 and 16. Therefore, we can take xa = 12 and xb= 16. Iteration 1. The estimate of the root is the midpoint of this interval
CE311K
DCM 2/8/09
Next, compute the product of the function values at the midpoint and lower bound of the interval
Thus, no sign change takes place in the left-hand portion of the interval. So, create a new interval by redefining a= c. Iteration 2. A new approximate root is computed
That is, compute the product of the function values at the midpoint and lower bound of the interval
Thus, a sign change takes place in the left-hand portion of the interval. So, create a new interval by redefining b= c. Iteration 3. A new approximate root is computed
CE311K
DCM 2/8/09
Note that the approximate error is always greater than the true error. This is an attractive characteristic since we cant always compute the true error. Table 2. Example of Bisection method Iteration 1 2 3 4 5 6 xa 12 14 14 14.5 14.75 14.75 xb 16 16 15 15 15 14.875 xc 14 15 14.5 14.75 14.875 14.8125 6.667 3.448 1.695 0.840 0.422 5.279 1.487 1.896 0.204 0.641 0.219
10 Approximate True
(%) Error
0.1 1 2 3 Iteration 4 5 6
CE311K
10
DCM 2/8/09
Newton's Method
In Newtons method a tangent line is extended from the current approximation of the root, [xi, f(xi)] to the point where the tangent crosses the x axis. Newtons method can be derived either form a geometrical argument or a Taylor series approach. The numerical approximation of the derivative of the function f(x) at the current approximation xi is
CE311K
11
DCM 2/8/09
Example:
Table 3. Newtons method for finding the root of f (x) = e Iteration I 0 1 2 3 4 0 0.500000 0.566311003 0.567243265 0.567143290 Approximate value
x
x.
Approximate error
1000 100 10
Error
1 0.1 0.01 0.001 0.0001 1 2 3 4 5 6 7 8 9 10 Iterate Fixed Point Method Newton's Method
Figure 7. Relative error for each iterate of finding a root of the function f (x) = e point iteration and Newtons methods.
x
x by fixed
CE311K
12
DCM 2/8/09
Why does Newtons method work so well? It has a quadratic convergence rate, rather than linear. To see this, consider the Taylor series approximation of the function
Now, if xi+1 is the true root of the equation, then f(xi+1) = 0, and
or, rearranging
In Newtons method we dont use all of the terms in the Taylor series. We only use the first and second terms to find the slope of the curve. If we solve for the next term in the Taylor series, this will give us an estimate of the error that we are incurring by truncating the series in our method. This estimate is
where xr is the true root. This formula shows us the error is proportional to the square of the previous error, and that if these errors are small (<1) then they are decreasing rapidly form one iteration to the next. In summary, Newtons method iteratively uses tangential lines that pass through the consecutive approximations of the root. The method needs a good initial guess, or else the iterative solution may diverge or converge to an alternate root. The convergence rate is high when it works.
CE311K
13
DCM 2/8/09
Example:
Several methods are available to solve systems of nonlinear equations, e.g., fixed-point iteration and Newtons methods. We will concentrate on Newtons method here. The first-order Taylor series for functions of two independent variables is
(2)
where
CE311K
14
DCM 2/8/09
Assuming that we have a guess for x1,I and x2,I that does not satisfy Equation (1), we want to find x1 and x2 such that
do satisfy Equation (1), or at least they provide a better approximation. If we sett the right-hand-side of Equation (2) equal to zero produces a set of linear, simultaneous equations in the xs.
Example:
CE311K
15
DCM 2/8/09
If one continues this process, the solution will converge to the values
Exercises
1. Given the following nonlinear equation:
(a) Write the equation for first iteration of Fixed point iteration (b) Write the equation for first iteration of Newtons method 2. Use fixed-point iteration to locate the root of:
CE311K
16
DCM 2/8/09
Use an initial guess of x0=0.5 and iterate until the approximate error is less than 0.01%. 3. Solve the following nonlinear equation using the fixed point iteration method:
graphically and (b) using the bisection method using a stopping criterion of 0.05%. (Root is between 1.0 and 0.0). 6. Determine the real roots of
to within 0.01% using Newtons method using initial guesses of (a) 0.5, (b) 1.5, and (c) 6.0.
CE311K
17
DCM 2/8/09
where c is the concentration of the pollutant in g/m3 the parameter values are V = 1x106 m3, Q = 1x105 m3/yr, W=1x106 g/yr, and k = 0.2 m0.5/g0.5/yr. The steady-state concentration can be found from the equation:
Only one of these equations will work all the time for initial guesses for c > 1. Select the correct one and demonstrate that it will work for an initial guess of c0=2.0 g/m3. 8. Use Newtons method to find the smallest value of x satisfying the following equation:
CE311K
18
DCM 2/8/09
Begin with the guess x = 0.0. Show the results of the computations for 2 iterations.
with
a) 0.0 _____;
b) 2.0 ______;
11. The values of x and the corresponding values of are x 0.0 1.0 0.5 0.75 The next value of x is a) 0.625 _____; b) 0.875 ______; c) 1.250 ______ f(x) 2.0 -1.0 0.125 -0.578125
12. A flat plate of mass m falling freely in air with a velocity V is subject to a downward gravitational force and an upward frictional drag force due to air. The drag force FD is given by the expression
CE311K
19
DCM 2/8/09
Terminal velocity is reached when the drag force equals the gravitational force
Find the terminal velocity using the Bisection Method if m = 1 kg and g = 9.8 m/s2. Use an initial interval of V = 0 to 200 m/s. Show your work for computing the first 2 iterations of the Bisection Method.
13. In the turbulent flow of fluid in a smooth pipe, the frictional force on the fluid is represented in terms of a friction factor f, which is positive and less than 0.1. The equation for f is
where Re is a constant, called the Reynolds number, which varies with the fluid properties, flow rate, and the pipe diameter. Use the Newton-Raphson method to obtain an approximate value for the friction factor (f) if the Re = 104. Show your computations for the first 2 iterations of Newton's method. Be sure to show all equations for the method. 14. The n-th root of a number A can be found by solving the equation
(b) Use the above result to solve for the cube root of A=161, use a starting value x0 = 6.0. Perform three Newton iterations, show all steps in the calculations. 15. Infiltration is the process of water penetrating from the ground surface into soil. Depending on the amount of infiltration and the physical properties of the soil, water may penetrate a few centimeters to several meters into a soil. The cumulative infiltration is the accumulated depth of water infiltrated during a given time period. Using approximations of the governing equations of mass and momentum conservation for soil water, hydrologists have developed equations to estimate infiltration. One of the most
CE311K 20 DCM 2/8/09
commonly used infiltration equations is the Green-Ampt equation, which assumes that there is a sharp boundary dividing dry soil from saturated soil. The Green-Ampt equation for the cumulative infiltration of water into soil after a period of time is
where: F K t = = = = = = the cumulative infiltration (cm) the hydraulic conductivity of the soil (cm/hr) time (hr) the suction head (cm) the change in soil moisture content from the dry soil to the saturated soil natural logarithm
ln
Compute the cumulative infiltration after one hour of infiltration into a soil that has the characteristics: K = = = 0.65 cm/hr 16.7 cm 0.34
Use Newton's Method and start at the value F = Kt. Be sure to show details of: a. the nonlinear function you solve, b. the equation you use for Newton's method c. the results for 3 Newton iterations. 16. Given the equation:
Suppose that you need to find the smallest value of x such that r = 0.7. Beginning with the guess x = 0.0, use the Newton method to determine the appropriate root. a) Write the complete expression that you are using in the Newton method to find the root. b) Show the results of the bisection computations for 3 iterations. 17. Solve the system of simultaneous nonlinear equations using Newton's method for systems:
CE311K
21
DCM 2/8/09
18. The following figure shows a rectangular open channel of constant dimensions.
Under uniform flow conditions the flow in the channel is given by Manning's equation
Q =
1 2 /3 SAR n
(1)
where S is the slope of the channel, A is the area of the channel, R is the hydraulic radius of the channel (the radius of a circle with equal area), and n is Manning's roughness coefficient. For a rectangular channel, the following relationships hold By B + 2y
A = By
and
R =
(2)
where y is the depth of the water in the channel. (a) Substitute the relationships from Equation (2) into Equation (1) and determine the nonlinear equation to be solved to find the depth of water y in the channel. (b) Draw a simple flow chart illustrating how you would use the bisection method to solve the equation you developed in part (a) for the depth of water in the channel. Be sure to include
CE311K
22
DCM 2/8/09
a mechanism in your method to stop the calculations when the desired accuracy has been achieved. (c) Use the data: Q = 14.15 m3/s B = 4.572 m n = 0.017 S = 0.0015 [1, 2] = initial interval for bisection method to solve for the depth of water in the channel using the bisection method. Take 3 iterations of the bisection method. 19. Newtons method for systems. Consider the system of simultaneous, nonlinear equations
(1)
(a) In very general terms (dont plug any number in yet!), what is the formula for Newtons , and how do you get it. method for 2 nonlinear equations? That is (b) For the two equations given above in (1), show the system of equations which must be solved in order to apply Newtons method (Dont plug in any numbers yet, just write down the equations using the functions from Equation (1) above.) (c ) Start with k=0, and solve to obtain (d) Now, knowing , what is the system of linear equations that you must ? What is the solution to that system of linear equations? you can calculate for k = 2 in a similar manner. What is the ? What is the solution to
system of linear equations that you must solve to obtain that system of linear equations?
(e) Draw a simple flowchart illustrating your algorithm for solving these equation.
CE311K
23
DCM 2/8/09
20. Explain how you would use Newton's method to solve the following simultaneous set of nonlinear equations:
CE311K
24
DCM 2/8/09