Presentation is loading. Please wait.

Presentation is loading. Please wait.

Finding roots of equations using the Newton-Raphson method

Similar presentations


Presentation on theme: "Finding roots of equations using the Newton-Raphson method"— Presentation transcript:

1 Finding roots of equations using the Newton-Raphson method

2 Home Quiz Introduction Petroleum Exercise: Preliminaries
Useful Info Resources Quiz

3 Learning objectives in this module
Develop problem solution skills using computers and numerical methods Review of the Newton-Raphson method Develop programming skills using FORTRAN FORTRAN elements in this module input/output loops format

4 Introduction Finding roots of equations is one of the oldest applications of mathematics, and is required for a large variety of applications, also in the petroleum area. A familiar equation is the simple quadratic equation (1) where the roots of the equation are given by  (2) These two roots to the quadratic equation are simply the values of x for which the equation is satisfied, i.e. the left side of eq. (1) is zero. How would you do this in Fortran? Think it through and see this of how it could be done Example More

5 Fortran Sample PROGRAM QUADRATIC REAL A, B, C, D, SOL1, SOL2
WRITE(*,*) ’Type the constants A,B and C’ READ* ,A,B,C D = B**2 - 4*A*C IF (D .LT. 0) THEN WRITE(*,*) ’The equation has a complex solution' ELSE SOL1 = (-B+SQRT(D)) / (2*A) SOL2 = (-B-SQRT(D)) / (2*A) WRITE(*,*) 'X1=',SOL1,'X2=',SOL2 ENDIF END

6 Introduction In a more general form, we are given a function of x, F(x), and we wish to find a value for x for which: The function F(x) may be algebraic or transcendental, and we generally assume that it may be differentiated. In practice, the functions we deal with in petroleum applications have no simple closed formula for their roots, as the quadratic equation above has. Instead, we turn to methods for approximation of the roots, and two steps are involved: 1 Finding an approximate root Refining the approximation to wanted accuracy The first step will normally be a qualified guess based on the physics of the system. For the second step, a variety of methods exists. Please see the textbook for a discussion of various methods. More

7 Introduction Here, we will concern ourselves with the Newton-Raphson method. For the derivation of the formula used for solving a one-dimensional problem, we simply make a first-order Taylor series expansion of the function F(x) (4) Let us use the following notation for the x-values: (5) Then, eq. (4) may be rewritten as (6) More

8 View Graphic Illustration
Introduction Setting Eq. (6) to zero and solving for xk+1 yields the following expression (7) This is the one-dimensional Newton-Raphson iterative equation, where represents the refined approximation at iteration level k+1, and is the approximation at the previous iteration level (k). View Graphic Illustration

9 See the Newton-Raphson method - animated
Graphic Illustration Graphically, the method is illustrated in the figure below. The first approximation (qualified guess) of the solution (x1) is around 1,6. The tangent to the function at that x-value intersects the x-axis at around 3,3 (x2). The tangent at that point intersects at around 2,4 (x3), and the fourth value (x4) is getting very close to the solution at around x=2,7 F(x) x See the Newton-Raphson method - animated HERE

10 Petroleum Exercise:Preliminaries
Equations of State (EOS) are used for description of PVT-behavior (Pressure-Volume-Temperature) of hydrocarbon gases. One such equation is the Beattie-Bridgeman equation: (8) P is pressure in atmospheres (atm) V is molar volume (liter/g mole) T is temperature (oK) R is the universal gas constant (0,08205 liter-atm / oK-g mole) Next

11 Beta Equations of State (EOS) are used for description of PVT-behavior (Pressure-Volume-Temperature) of hydrocarbon gases. One such equation is the Beattie-Bridgeman equation: (8) P is pressure in atmospheres (atm) V is molar volume (l/g mole) T is temperature (oK) R is the universal gas constant (0,08205 liter-atm / oK-g mole) A0, B0, a, b, c are gas specific constants Next

12 Gamma Equations of State (EOS) are used for description of PVT-behavior (Pressure-Volume-Temperature) of hydrocarbon gases. One such equation is the Beattie-Bridgeman equation: (8) P is pressure in atmospheres (atm) V is molar volume (l/g mole) T is temperature (oK) R is the universal gas constant (0,08205 liter-atm / oK-g mole) A0, B0, a, b, c are gas specific constants Next

13 Delta Equations of State (EOS) are used for description of PVT-behavior (Pressure-Volume-Temperature) of hydrocarbon gases. One such equation is the Beattie-Bridgeman equation: (8) P is pressure in atmospheres (atm) V is molar volume (l/g mole) T is temperature (oK) R is the universal gas constant (0,08205 liter-atm / oK-g mole) A0, B0, a, b, c are gas specific constants Next

14 Petroleum Exercise:Preliminaries
After solving for the root of the eq. (8), ie. for the value for V that satisfies the equation for one particular set of pressure and temperature, we may find the corresponding compressibility factor (Z-factor) for the gas using the formula (the gas law for a real gas): (12) PV = ZRT Which can be rearranged to ... (obviously) Z = PV RT Next

15 Petroleum Exercise:Preliminaries
The procedure for the exercise is described in the following. First, we rewrite the Beattie-Bridgeman equation as: (13) Then, we take the derivative of the function F(V) at constant P and T Try yourself! What is the derivative of F (V)? then check the Answer (click)

16 Quiz Did you really try?? Click the correct solution and see if you still know your maths A) B)

17 Right Answer Right Answer!! BACK

18 Wrong Answer Sorry, Wrong Answer!! BACK

19 Petroleum Exercise:Preliminaries
Now, the derivate of the function F(V) at constant P & T being (14) using the Newton-Raphson formula of eq. (7), we may find the root of Eq. (13) iteratively and after reducing the fraction, we get where k is the iteration counter More

20 Petroleum Exercise:Preliminaries
For the first iteration (k=1) we need a start value V1. Here, we estimate a value using the ideal gas law (assuming Z=1): PV=RT or V1=RT / P The iterative procedure is terminated when the relative change in V is less than a prescribed convergence criterion, e, i.e.

21 Petroleum Exercise Tasks to be completed
Make a FORTRAN program that uses the Newton-Raphson method to solve the Beattie-Bridgeman equation for molar volume (V ) for any gas (i.e.. for any set of the parameters A0, B0, a, b, c) at a given pressure (P ) and a given temperature (T ). After finding the volume (V ), the compressibility factor (Z ) should be computed. The computer program will read all parameters, and pressure and temperature, from the input file, and should write the computed parameters, pressure and temperature, and computed compressibility factor, for each set of pressure and temperature to the output file. Run the computer program for This data set Make a plot of compressibility factor vs. pressure for the two different temperatures (on the same figure). 1 2 3

22 Petroleum Exercise (continued)
P (atm) T (C) 1 2 5 10 20 40 60 80 100 120 140 160 180 200 Use the following set of data for the gas (methane) Make computations for the following pressures and temperatures. (Remember that K=273,15+0C) Parameter Value Ao 2,2789 Bo 0,05587 a 0,01855 b -0,01587 c 128000 Use a convergence criterion of , and set max allowed number of iterations to 20 Useful info and tip on the Fortran Program HERE

23 For the Newton-Raphson program
Useful Info For the Newton-Raphson program Include an input and an output file. For the iterative operation, the DO loop is recommended. The convergence criterion should be tested with the IF statement Find a reasonable format in which to present your calculations All clear? Go to Work!! Resources

24 Resources Introduction to Fortran Fortran Template here
The whole exercise in a printable format here Web sites Numerical Recipes Fortran Tutorial Professional Programmer's Guide to Fortran77 Programming in Fortran77

25 Quiz This section includes a quiz on the topics covered by this module. The quiz is meant as a control to see if you have learned some of the most important features Hit object to start quiz

26 General information About the author Title:
Finding roots of equations using the Newton-Raphson method Teacher(s): Professor Jon Kleppe Assistant(s): Per Jørgen Dahl Svendsen Abstract: Provide a good background for solving problems within petroleum related topics using numerical methods 4 keywords: Newtons Method, Loops, Fortran, Input/Output Topic discipline: Level: 2 Prerequisites: None Learning goals: Develop problem solution skills using computers and numerical methods Size in megabytes: 0.7 MB Software requirements: MS Power Point 2002 or later, Flash Player 6.0 Estimated time to complete: Copyright information: The author has copyright to the module and use of the content must be in agreement with the responsible author or in agreement with About the author

27 FAQ No questions have been posted yet. However, when questions are asked they will be posted here. Remember, if something is unclear to you, it is a good chance that there are more people that have the same question For more general questions and definitions try these Dataleksikon Webopedia Schlumberger Oilfield Glossary

28 References W. H. Preuss, et al., “Numerical Recipes in Fortran”, 2nd edition Cambridge University Press, 1992 References to the textbook : Newton-Raphson Method Using Derivative: page 355 The Textbook can also be accessed online: Numerical Recipes in Fortran

29 Summary Subsequent to this module you should...
be able to translate a problem to Fortran code write and handle DO loops have a feel for the output format know the conditional statements and use the IF structure

30 Newton-Raphson Method Movie
(Just click on image to start movie) Back


Download ppt "Finding roots of equations using the Newton-Raphson method"

Similar presentations


Ads by Google