SIG4040 Applied Computing in Petroleum. Newton-Rapson's Method. Norges
teknisk-naturvitenskapelige universitet. Professor Jon Kleppe. Institutt for ...
SIG4040 Applied Computing in Petroleum Newton-Rapson’s Method
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
!b ± b ! 4ac . 2a 2
x=
(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) + hF !(x) .
(4)
Let us use the following notation for the x-values:
xk = x x k +1 = x + h
(5)
Then, Eq. (4) may be rewritten as Norges teknisk-naturvitenskapelige universitet Institutt for petroleumsteknologi og anvendt geofysikk
Professor Jon Kleppe
SIG4040 Applied Computing in Petroleum Newton-Rapson’s Method
2
F(x k +1 ) = F(x k ) + ( x k +1 ! x k )F " (x k ) . Setting Eq. (6) to zero and solving for x k +1 yields the following expression: x k +1 = x k !
(6)
F(x k ) . F "(x k )
(7)
This is the one-dimensional Newton-Raphson iterative equation, where x k +1 represents the refined approximation at iteration level k+1, and x k is the approximation at the previous iteration level (k). Graphically, the method is illustarted 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 ( x 2 ). The tangent at that point intersects at around 2,4 ( x 3 ), and the fourth value ( x 4 ) is getting very close to the solution at around x=2,7 F(x)
x4 x1
x2
x
x3
Petroleum exercise Equations of State (EOS) are used for description of PVT-behavior (Pressure-VolumeTemperature) of hydrocarbon gases. One such equation is the Beattie-Bridgeman equation: P=
RT ! " # + 2+ 3+ 4 V V V V
(8)
where P is pressure (atm), V is molar volume (liter/g mole), T is temperature ( °K ), R is the universal gas constant (0,08205 liter-atm/ °K -g mole), and the temperature dependent parameters for the gas, ! , ! and ! , are expressed by the following formulas: ! = RTB0 " A0 " ! = " RTB0 b + A0 a "
!=
Norges teknisk-naturvitenskapelige universitet Institutt for petroleumsteknologi og anvendt geofysikk
RB0 bc T2
Rc T2 RcB0 T2
(9) (10) (11)
Professor Jon Kleppe
SIG4040 Applied Computing in Petroleum Newton-Rapson’s Method
3
where A0 , B0 , a, b, and c are constants (different for each gas). 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): Z=
PV RT
(12)
The procedure for the exercise is described in the following. First, we rewrite the BeattieBridgeman equation as:
F(V ) =
RT ! " # + 2 + 3 + 4 $P =0. V V V V
(13)
Then, we take the derivative of the function F(V) at constant P and T:
F !(V ) = "
RT 2# 3$ 4% " " " V 2 V 3 V4 V5
(14)
Using the Newton-Raphson formula of Eq. (7), we may find the root of Eq. (13) iteratively: F (Vk ) F "(Vk )
(15)
RTVk4 + !Vk3 + "Vk2 + #Vk $ PVk5 RTVk3 + 2 !Vk2 + 3"Vk + 4#
(16)
Vk +1 = Vk !
or Vk +1 = Vk +
where k is the iteration counter. 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): P=
RT V
(17)
V1 =
RT P
(18)
or
The iterative procedure is terminated when the relative change in V is less than a prescribed convergence criterium, ε, ie.: Vk +1 ! Vk "# Vk +1
Norges teknisk-naturvitenskapelige universitet Institutt for petroleumsteknologi og anvendt geofysikk
(19)
Professor Jon Kleppe
SIG4040 Applied Computing in Petroleum Newton-Rapson’s Method
4
Tasks to be completed 1. Make a FORTRAN program that uses the Newton-Raphson method to solve the BeattieBridgeman 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 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 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 Ao Bo a b c
Value 2,2789 0,05587 0,01855 -0,01587 128000
and make computations for the following pressures and temperatures: (remember that °K = 273, 13 + °C ): P (atm) 1 2 5 10 20 40 60 80 100 120 140 160 180 200 1 2 5 10 20 40 60 80 100 120 140 160 180 200
T ( °C ) 0 0 0 0 0 0 0 0 0 0 0 0 0 0 200 200 200 200 200 200 200 200 200 200 200 200 200 200
Use a convergence criterium of 0,000001, and set the maximum allowed number of iterations to 20. Norges teknisk-naturvitenskapelige universitet Institutt for petroleumsteknologi og anvendt geofysikk
Professor Jon Kleppe