+ All Categories
Home > Documents > Finding roots of equations using the Newton-Raphson …kleppe/TPG4155/o2.pdf · Execise 2:...

Finding roots of equations using the Newton-Raphson …kleppe/TPG4155/o2.pdf · Execise 2:...

Date post: 06-Apr-2018
Category:
Upload: hamien
View: 217 times
Download: 1 times
Share this document with a friend
4
TPG4155 Applied Computing in Geoscience and Petroleum 2003 Execise 2: Newton-Rapson’s Method Norges teknisk-naturvitenskapelige universitet Professor Jon Kleppe Institutt for petroleumsteknologi og anvendt geofysikk 29.08.03 1 Finding roots of equations using the Newton-Raphson method 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 eguation ax 2 + bx + c = 0 (1) where the roots of the equation are given by x = -b ± b 2 - 4 ac 2 a . (2) These two roots to the quadratic equation are simply the values of x for which the equation is satisfied, ie. the left side of Eq. (1) is zero. 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 F ( x ) = 0 . (3) 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 2. 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. Here, we will concern ourselves with the Newton-Raphson method. For the derivation of the fomula used for solving a one-dimensional problem, we simply make a first-order Taylor series expansion of the function F(x) F ( x + h) = F ( x ) + h ¢ F ( x ) . (4) Let us use the following notation for the x-values: x k = x x k + 1 = x + h (5) Then, Eq. (4) may be rewritten as F ( x k + 1 ) = F ( x k ) + x k + 1 - x k ( ) ¢ F ( x k ) . (6) Setting Eq. (6) to zero and solving for x k + 1 yields the following expression:
Transcript
Page 1: Finding roots of equations using the Newton-Raphson …kleppe/TPG4155/o2.pdf · Execise 2: Newton-Rapson’s Method ... Make a FORTRAN program that uses the Newton-Raphson method

TPG4155 Applied Computing in Geoscience and Petroleum 2003Execise 2: Newton-Rapson’s Method

Norges teknisk-naturvitenskapelige universitet Professor Jon KleppeInstitutt for petroleumsteknologi og anvendt geofysikk 29.08.03

1

Finding roots of equations using the Newton-Raphson method

IntroductionFinding roots of equations is one of the oldest applications of mathematics, and is required for alarge variety of applications, also in the petroleum area. A familiar equation is the simplequadratic eguation

ax2 + bx + c = 0 (1)

where the roots of the equation are given by

x =-b ± b2 - 4ac

2a . (2)

These two roots to the quadratic equation are simply the values of x for which the equation issatisfied, ie. the left side of Eq. (1) is zero.

In a more general form, we are given a function of x, F(x), and we wish to find a value for x forwhich

F(x) = 0 . (3)

The function F(x) may be algebraic or transcendental, and we generally assume that it may bedifferentiated.

In practice, the functions we deal with in petroleum applications have no simple closed formula fortheir roots, as the quadratic equation above has. Instead, we turn to methods for approximation ofthe roots, and two steps are involved:

1. Finding an approximate root2. Refining the approximation to wanted accuracy

The first step will normally be a qualified guess based on the physics of the system. For thesecond step, a variety of methods exists. Please see the textbook for a discussion of variousmethods.

Here, we will concern ourselves with the Newton-Raphson method. For the derivation of thefomula used for solving a one-dimensional problem, we simply make a first-order Taylor seriesexpansion of the function F(x)

F(x + h) = F(x) + h ¢ F (x) . (4)

Let us use the following notation for the x-values:

xk = xxk +1 = x + h (5)

Then, Eq. (4) may be rewritten as

F(xk +1) = F(xk) + xk +1 - xk( ) ¢ F (xk) . (6)Setting Eq. (6) to zero and solving for

xk +1 yields the following expression:

Page 2: Finding roots of equations using the Newton-Raphson …kleppe/TPG4155/o2.pdf · Execise 2: Newton-Rapson’s Method ... Make a FORTRAN program that uses the Newton-Raphson method

TPG4155 Applied Computing in Geoscience and Petroleum 2003Execise 2: Newton-Rapson’s Method

Norges teknisk-naturvitenskapelige universitet Professor Jon KleppeInstitutt for petroleumsteknologi og anvendt geofysikk 29.08.03

2

xk +1 = xk -F(xk )

¢ F (xk). (7)

This is the one-dimensional Newton-Raphson iterative equation, where

xk +1 represents the refinedapproximation at iteration level k+1, and

xk is the approximation at the previous iteration level (k).Graphically, the method is illustarted in the figure below. The first approximation (qualifiedguess) of the solution (

x1) is around 1,6. The tangent to the function at that x-value intersects thex-axis at around 3,3 (

x2 ). The tangent at that point intersects at around 2,4 (

x3 ), and the fourthvalue (

x4 ) is getting very close to the solution at around x=2,7

Petroleum exerciseEquations of State (EOS) are used for description of PVT-behavior (Pressure-Volume-Temperature) of hydrocarbon gases. One such equation is the Beattie-Bridgeman equation:

P =RTV

+b

V2 +gV3 +

dV4 (8)

where P is pressure (atm), V is molar volume (liter/g mole), T is temperature (°K ), R is theuniversal gas constant (0,08205 liter-atm/°K -g mole), and the temperature dependentparameters for the gas, b , g and d , are expressed by the following formulas:

b = RTB0 - A0 -RcT2 (9)

g = - RTB0b + A0a -RcB0T 2 (10)

d =RB0bc

T 2 (11)

where A0 , B0 , a, b, and c are constants (different for each gas).

F(x)

x

x1

x2

x3

x4

Page 3: Finding roots of equations using the Newton-Raphson …kleppe/TPG4155/o2.pdf · Execise 2: Newton-Rapson’s Method ... Make a FORTRAN program that uses the Newton-Raphson method

TPG4155 Applied Computing in Geoscience and Petroleum 2003Execise 2: Newton-Rapson’s Method

Norges teknisk-naturvitenskapelige universitet Professor Jon KleppeInstitutt for petroleumsteknologi og anvendt geofysikk 29.08.03

3

After solving for the root of the Eq. (8), ie. for the value for V that satisfies the equation for oneparticular set of pressure and temperature, we may find the corresponding compressibilityfactor (Z-factor) for the gas using the formula (the gas law for a real gas):

Z =PVRT

(12)

The procedure for the exercise is described in the following. First, we rewrite the Beattie-Bridgeman equation as:

F(V ) =RTV +

bV 2 +

gV 3 +

dV 4 - P = 0 . (13)

Then, we take the derivative of the function F(V) at constant P and T:

¢ F (V ) = -RTV 2 -

2bV 3 -

3gV 4 -

4dV 5 (14)

Using the Newton-Raphson formula of Eq. (7), we may find the root of Eq. (13) iteratively:

Vk +1 = Vk -F (Vk )

¢ F (Vk)(15)

or

Vk +1 = Vk +RTVk

4 + bVk3 + gVk

2 + dVk - PVk5

RTVk3 + 2bVk

2 + 3gVk + 4d(16)

where k is the iteration counter. For the first iteration (k=1) we need a start value V1. Here, weestimate a value using the ideal gas law (assuming Z=1):

P =RTV

(17)

or

V1 =RTP (18)

The iterative procedure is terminated when the relative change in V is less than a prescribedconvergence criterium, e, ie.:

Vk +1 - Vk

Vk +1£ e (19)

Tasks to be completed1. Make a FORTRAN program that uses the Newton-Raphson method to solve the Beattie-

Bridgeman equation for molar volume (V) for any gas (ie. 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

Page 4: Finding roots of equations using the Newton-Raphson …kleppe/TPG4155/o2.pdf · Execise 2: Newton-Rapson’s Method ... Make a FORTRAN program that uses the Newton-Raphson method

TPG4155 Applied Computing in Geoscience and Petroleum 2003Execise 2: Newton-Rapson’s Method

Norges teknisk-naturvitenskapelige universitet Professor Jon KleppeInstitutt for petroleumsteknologi og anvendt geofysikk 29.08.03

4

parameters, and pressure and temperature, from the input file, and should write thecomputed parameters, pressure and temperature, and computed compressibility factor, foreach set of pressure and temperature to the ouput file.

2. Run the computer program for the data set below.3. Make a plot of compressibility factor vs. pressure for the two different temperatures (on

the same figure).

Use the following set of data for the gas (methane):

Parameter ValueAo 2,2789Bo 0,05587a 0,01855b -0,01587c 128000

and make computations for the following pressures and temperatures: (remember that°K = 273, 13+ °C):

P (atm) T (°C )1 02 05 010 020 040 060 080 0

100 0120 0140 0160 0180 0200 01 2002 2005 20010 20020 20040 20060 20080 200

100 200120 200140 200160 200180 200200 200

Use a convergence criterium of 0,000001, and set the maximum allowed number of iterations to20.

The exercise is handed out on August 29, 2003Last day of approval of exercise no. 2: September 9, 2003


Recommended