APPENDIX B Evaluating implicit equations There is a certain amount of difficulty for some students in understanding the difference between implicit and explicit equations, and in knowing how to evaluate equations of the implicit type. Most people are comfortable with explicit equations (i.e., equations that can be made explicit), but implicit equations occur commonly enough in mathematical modeling that an aspiring modeler should have a reasonable understanding of how to approach them. An explicit equation is one in which the independent variables can all be put on one side of the equation, and the unknown can be put on the other side. For example, y = x 2 + 2x + 3, f (t) = 5e αt, f (z) = A sin(nπz), (B.1) (B.2) (B.3) In each of these, a value can be substituted into the independent variable on the right-hand side (for x, t, orz) and, by performing the indicated operations, a value can be computed for the dependent variable on the left-hand side (y, f (t), or f (z), respectively). In contrast, implicit equations cannot be solved in a closed-form sense. Take, for example, the implicit equation, λβ = tan β, (B.4) where λ is a constant, or the equation (Fairley, 2009), θ L = 1 e β (B.5) β where θ L is a known (observed) quantity. In neither of these equations is there any way to get the desired quantity, β, by itself on one side of the equation so that it may be conveniently calculated. In particular, Equation B.4 comes up quite often in mathematical models of physical systems, and implicit equations in general are encountered often enough that approaches must be found for evaluating them. To the best of my knowledge, there are (at least) four methods for evaluating implicit equations; they are trialand-error, the graphical method, iteration, and Newton s method. I will present a brief synopsis of each of these approaches in the following text. Models and Modeling: An Introduction for Earth and Environmental Scientists, First Edition. Jerry P. Fairley. 2017 John Wiley & Sons, Ltd. Published 2017 by John Wiley & Sons, Ltd. Companion website: www.wiley.com/go/fairley/models 238
Evaluating implicit equations 239 B.1 Trial and error Trial and error is probably the most obvious method of solving implicit equations; many of us learned to make a good guess at a value and improve it while trying to shortcut problems in a High School algebra or trigonometry class. However, guessing a number, then making another guess and seeing if the answer is closer than the previous guess, is not a very efficient way of going about finding trialand-error solutions to equations. Probably the easiest and most straightforward waytoapplytrialanderrortoanequationistofirstdecideinwhatrangeof values the answer is expected to lie. Next, decide what precision is required for the application (usually trial-and-error methods work best in situations where the requirements for precision are modest); for example, say you would like the answer to a precision of 0.01. Finally, write a simple computer program (e.g., in Fortran, C++, or Matlab) or use a spreadsheet program to calculate all the values in between the two limits with a step size of 0.01 (or whatever precision you decided on). The answer can then be found by simply reading down through the list of values and selecting the closest one. If the number of values would be too great for such a brute force approach, one can do it in phases, starting with a large range but a coarse step size, then identifying a smaller range and using a finer step size. Trial and error is not a very elegant way to seek a solution to an implicit equation, but it is simple and understandable. Although the other methods discussed later are more elegant and satisfying (at least to my mind), trial and error is good for quick, one-time estimates, or as a fallback method when all else fails. B.2 The graphical method Next to trial and error, the graphical method is probably the oldest approach to finding solutions to implicit equations, and it is generally easy to apply. Unfortunately, the precision that can be obtained from this method is limited; however, it is useful in situations where exact solutions are not required, or as a first step for gaining a good initial guess before refining it with either iteration or Newton s method. Simply stated, the method treats each side of the implicit equation as an explicit equation, and each side is plotted separately, but on the same set of axes. The locations of the intersections of the two plots are the solutions to the complete implicit equation. For a concrete example, take the following equation: x = 4π cos x. (B.6) Plotting the left-hand side of Equation B.6 gives a straight line running from y = 4π (at x = 4π) toy = 4π (at x = 4π). On the right-hand side is a cosine
240 Appendix B function with amplitude 4π that runs through four complete cycles on the interval 4π x 4π. When plotted on the same set of axes, the two functions cross at eight points, four negative and four positive values of x, the largest of which is at 4π. (For values of x < 4π or x > 4π, the linear function is less than or greater than, respectively, the amplitude of the cosine function, and no intersections are possible.) As mentioned before, this method is not terribly precise. It is easy to use, and, besides being intuitive, it has the advantage of drawing the practitioner s attention to equations that have multiple roots. For these reasons, it is a good idea to practice this method and apply it to unfamiliar equations, or in situations where it is not clear what the structure of the solution(s) of a particular equation may be. B.3 Iteration Iteration (sometimes known as fixed-point iteration, Logan (2006)), is a far more elegant approach to finding solutions to an implicit equation than trial and error. Unfortunately, its success is dependent on way the equation is arranged and (in some cases), on having an appropriate initial guess or estimate of the final answer. To apply iteration, you should get the unknown alone on one side of the equation (of course, it will also be on the other side of the equation). Using Equation B.5 as an example, we can rearrange slightly to get the following: β = 1 e β θ L. (B.7) Now an initial guess is substituted for β on the right-hand side, the indicated operations are performed, and a value for the β on the left-hand side is found. Of course, this second β will not be the same as the initial guess for β (unless the initial guess was extremely lucky indeed). Therefore, we take this new value of β and substitute it on the right-hand side and recalculate the β on the lefthand side. We keep iterating in this fashion until either the difference between two successive iterations drops below a predetermined target precision (i.e., the iteration converges) or we see that the iterations are diverging (getting larger and larger or smaller and smaller without bound). Occasionally, we may find that the solution bounces around without ever converging on any specific value. If the solution fails to converge, we either need to rearrange our equation in a manner more suited to iteration, or use another approach to find a solution. According to Logan (2006), the method converges to a solution x, for any initial guess that is sufficiently close to the final value, provided the absolute value of the first derivative of the function, evaluated at x,islessthan1. Iteration has the advantage of (usually) being quick to use; in the example given in Equation B.7, six iterations are sufficient to obtain five decimal places
Evaluating implicit equations 241 of precision (with θ L = 0.2 and an initial guess of β 0 = 0.5; the final β 6 = 4.96511). It is also easy to obtain values to arbitrarily high precision. As noted, its drawbacks are that it doesn t always converge, and the method can be sensitive to the choice of the initial guess. For equations that have multiple roots or even, like Equation B.4, have an infinite number of roots, it may be difficult to find an initial guess that converges to the root of interest. When the method works, however, it is probably the quickest and most accurate of the methods presented here, so it is well worth trying. Sometimes, a few hand calculations will show that the method will work; once this is established, it is easy to throw together a quick-and-dirty computer program if many estimates need to be made. B.4 Newton s method Newton s method is another iterative method for finding approximations of the roots of an equation; it is sometimes called Newton Raphson iteration, after sir Isaac Newton and Joseph Raphson, an English mathematician who refined and simplified Newton s original method. Starting from an initial guess (n = 0), Newton iteration calculates an improved estimate of the root using the formula x n+1 = x n f (x n) f (x n ), (B.8) where the prime indicates the first derivative of the function f (x), the roots of which are being sought. Newton s method usually converges rapidly, and it is much more likely to converge than the iterative method described in the previous section (Newton s method works for any sufficiently well-behaved function). It is also easy to refine the approximation to the solution to any desired degree, and the method can be extended to systems of equations (Newton Raphson iteration is the solver of choice for many multiphase flow and transport models). The main drawbacks of the method are that it is somewhat more difficult to program than either trial and error or iteration (although not prohibitively difficult), and it requires careful consideration of the initial guess in order to converge to the desired root in cases when a function has more than one root. One additional difficulty is that, in order to find the first derivative of the function f (x) and evaluate it at x n, the user may need to resort to implicit differentiation (the technique of implicit differentiation is described in almost any standard calculus textbook). Despite these difficulties, which are generally slight, Newton iteration is probably the most commonly used root-finding method, and its many positive attributes far outweigh any minor difficulties in its application. You should most certainly learn how to use it and write a root-finding program of your own for future use.
242 Appendix B References Fairley, J.P. (2009) Modeling fluid flow in a heterogeneous, fault-controlled hydrothermal system. Geofluids, 9, 153 166, doi:10.1111/j.1468 8123.2008.00236.x. Logan, J.D. (2006) A First Course in Differential Equations, Springer Science+Business Media, LLC, New York.