Chapter 7 Differentiation and Integration
Download
Report
Transcript Chapter 7 Differentiation and Integration
Chapter 7 Differentiation and
Integration
• Finite-difference differentiation
df ( x ) f ( x x ) f ( x )
forward difference
dx
x
df ( x ) f ( x ) f ( x x )
backward difference
dx
x
df ( x ) f ( x x ) f ( x x )
two - step method
dx
2x
7- 1
Example: Evaporation Rates
Table: Saturation Vapor Pressure (es) in
mm Hg as a Function of Temperature (T) in °C
T(°C)
20
21
22
23
24
25
es(mm Hg)
17.53
18.65
19.82
21.05
22.37
23.75
7- 2
The slope of the saturation vapor pressure curve at
22°C (3 methods) :
des es (23) es (22) 21.05 19.82
forward
1.23 mm Hg/C
dT
23 22
1
des es (22) es (21) 19.82 18.65
backward
1.17 mm Hg/C
dT
22 21
1
des es (23) es (21) 21.05 18.65
two - step
1.20 mm Hg/C
dT
23 21
2
The true value is 1.20 mm Hg/°C, so the two-step
method provides the most accurate estimate.
7- 3
Differentiation Using a Finitedifference Table
Example: Finite-difference Table for Specific
Enthalpy (h) in Btu/lb and Temperature (T) in ºF
T
h
800
1305
Δh
Δ2h
Δ3h
Δ4h
155
1000
1460
-30
125
1200
1585
25
-5
120
1400
1705
-20
5
0
120
1600
1825
7- 4
• For example, at a temperature of 1200 ºF, the
forward, backward, and two-step methods yield:
h 1705 1585 120
cp
0.6 Btu/lb/ F
T 1400 1200 200
cp
h 1585 1460 125
0.625 Btu/lb/ F
T 1200 1000 200
h 1705 1460 245
cp
0.6125 Btu/lb/ F
T 1400 1000 400
• The rate of change of cp at T= 1200 ºF is
2h
5
2
0
.
025
Btu/lb/(
F)
T 2 200
7- 5
Differentiating an Interpolating Polynomial
f ( x) bn xn bn1xn1 bn2 xn2 ... b1x b0
The derivative:
df ( x)
nbn x n 1 (n 1)bn 1 x n 2 ... b1
dx
Gregory-Newton interpolation polynomial:
f(x) a1 a2 ( x x1 ) a3 ( x x1 )( x x2 )
a4 ( x x1 )( x x2 )( x x3 )
It is more difficult to evaluate the derivative:
df ( x )
a2 a3[( x x2 ) ( x x1 )] a4 [( x x2 )( x x3 )
dx
( x x1 )( x x3 ) ( x x1 )( x x2 )]
7- 6
Differentiation Using Taylor Series
Expansion
df ( x )
d 2 f ( x ) ( x )2 d 3 f ( x ) ( x )3
f ( x x ) f ( x )
x
...
2
3
dx
dx
2!
dx
3!
T runcatingtermswith thesecondderivativeand higher derivatives :
df ( x )
f ( x x ) f ( x )
x
dx
T hen,we get
df ( x ) f ( x x ) f ( x )
f ' ( x)
dx
x
It is thesame as theforwardfinite- difference.
7- 7
• The second-order approximation:
df ( x ) f ( x x ) f ( x ) d 2 f ( x ) x
dx
x
dx2 2!
Withforward difference:
d 2 f ( x ) f ' ( x x ) f ' ( x )
2
dx
x
f ( x 2x ) 2 f ( x x ) f ( x )
( x ) 2
The second-order approximation of the first
derivative with forward difference:
df ( x ) f ( x 2x ) 4 f ( x x ) 3 f ( x )
dx
2x
7- 8
• The second-order approximation of the second
derivative with forward difference:
d 2 f ( x) f ( x 3x) 4 f ( x 2x) 5 f ( x x) 2 f ( x)
2
dx
(x) 2
• The first-order and second-order approximation of
the first derivative with backward difference:
df ( x) f ( x) f ( x x)
dx
x
df ( x) 3 f ( x) 4 f ( x x) f ( x 2x)
dx
2x
7- 9
• The first-order and second-order approximation of
the second derivative with backward difference:
d 2 f ( x) f ( x) 2 f ( x x) f ( x 2x)
2
dx
(x) 2
d 2 f ( x) 2 f ( x) 5 f ( x x) 4 f ( x 2x) f ( x 3x)
2
dx
(x) 2
• How to derive
(for reference only)
f ( x 3x ) f ( x ) f ' ( x ) 3x f ' ' ( x ) 92 ( x )2
f ( x 2x ) f ( x ) f ' ( x ) 2x f ' ' ( x ) 2( x )2
f ( x x ) f ( x ) f ' ( x ) x f ' ' ( x ) 12 ( x ) 2
1
[ f ( x 3x ) 4 f ( x 2x ) 5 f ( x x ) 2 f ( x x )]
( x ) 2
1
2
9
[
f
(
x
)
3
xf
'
(
x
)
(
x
)
f ' ' ( x)
2
( x ) 2
4 f ( x ) 8xf ' ( x ) 8( x ) 2 f ' ' ( x )
- 5 f ( x ) 5xf ' ( x ) 25 ( x )2 f ' ' ( x ) 2 f ( x )]
f ' ' ( x)
7- 10
• The first-order and second-order approximation of
the first derivative with the two-step method:
df ( x) f ( x x) f ( x x)
dx
2x
df ( x) f ( x 2x) 8 f ( x x) 8 f ( x x) f ( x 2x)
dx
12x
• The first-order and second-order approximation of
second derivative with the two-step method:
d 2 f ( x) f ( x x) 2 f ( x) f ( x x)
dx2
(x) 2
d 2 f ( x) f ( x 2x) 16 f ( x x) 30 f ( x) 16 f ( x x) f ( x 2x)
dx2
12(x) 2
7- 11
Example: Evaporation Rates
Second-order with forward, backward, two-step:
df ( x) es (24) 4es (23) 3es (22)
dx
2(1)
22.37 4(21.05) 3(19.82)
1.185 mm Hg/C
2(1)
df ( x) 3es (22) 4es (21) es (20)
dx
2(1)
3(19.82) 4(18.65) 17.53
1.195 mm Hg/ C
2(1)
df ( x) es (24) 8es (23) 8es (21) es (20)
dx
12(1)
(22.37) 8(21.05) 8(18.65) (17.53)
1.19667mm Hg/ C
12(1)
The true value at T = 22ºC is 1.2 mm Hg/ºC
7- 12
Numerical Integration
• The area under the curve f(x) between x=a and x=b:
b
integral f ( x)dx
a
• Example: the volume rate of flow (Q) of water in a channel
or through a pipe is the integral of the velocity (V) and the
incremental area (dA):
Q VdA
7- 13
Interpolation Formula Approach
The Gregory-Newton interpolation polynomial:
f ( x ) a1 a2 ( x x1 ) a3 ( x x1 )( x x2 ) ...
an 1 ( x x1 )( x x2 )...(x xn )
After a1 , a2 , an 1 are determined, we can rearrange
it toform an nth - order polynomial:
f ( x ) b1 x n b2 x n 1 ... bn 1
T hen,it can be integratedanalytically as follows:
b1 n 1 b2 n
f ( x )dx n 1 x n x ... bn1 x c
7- 14
Trapezoidal Rule
xn
x1
f ( xi 1 ) f ( xi )
f ( x)dx ( xi 1 xi )
2
i 1
n 1
7- 15
• Another way to get the trapezoidal formula
The linear polynomial passing the data points:
f ( xi 1 ) f ( xi )
f ( x) f ( xi )
( x xi )
xi 1 xi
Integrating f ( x ) between two pointsa and b, we get
b
b a (b a )
f
(
x
)
dx
[
( f ( xi 1 ) f ( xi )) xi 1 f ( xi ) xi f ( xi 1 )]
a
xi 1 xi
2
Let b xi 1 and a xi , we get
xi 1
xi
f ( x )dx
xi 1 xi
[ f ( xi 1 ) f ( xi )]
2
7- 16
• The absolute value of the upper bound on
the error for the Trapezoidal rule is:
( xi 1 xi )3
error
f ''(xj )
12
where f ' ' ( x j ) max f ' ' ( x )
xi x xi 1
7- 17
Example: Trapezoidal Rule for Integration
f ( x) x3 5x 2 4x 3
• n=4
• The trapezoidal rule provides
2 1
3 2
43
1 f ( x)dx 2 [3 (1)] 2 [1 (3)] 2 [3 (3)]
1 ( 2) 0 1
4
7- 18
7- 19
Example: Flow Rate
• The flow rate (Q) of an incompressible fluid is given by
the integral.
Q VdA
in which V is the velocity and A is the area.
• For a circular pipe of radius r, the incremental area dA is
equal to 2πrdr.
r0
Q V( 2rdr)
0
7- 20
• Table 6: The Data for Estimating the Flow Rate of a Fluid
in a Circular Piple
i
ri (ft)
Vi (fps)
1
0
10.000
2
1/12
9.722
3
1/6
8.889
4
1/4
7.500
5
1/3
5.556
6
5/12
3.056
7
1/2
0.
7- 21
• For a pipe of diameter of 1 ft
trapezoidal rule:
r 6
Q
[Vi (2π ri ) Vi 1 (2π ri 1 )]
2 i 1
Q
Q
1
) 6
12
[Vi ri Vi 1ri 1 ]
2
i 1
2π (
π
1
1
1
{100 9.722 9.722 8.889
12
12
12
6
1
1 1
1
8.889 7.5 7.5 5.556
6
4 4
3
1
5
5 1
5.556 3.056 3.056 0 }
3
12
12 2
3.818ft3/sec
7- 22
Simpson’s Rule
• Simpson’s rule:
b
a
f ( x)dx
x
x
[ f (a) 4 f (a x) f (b)]
3
ba
2
where
• Simpson’s rule can only be applied when there are
an even number of subintervals:
xn
x1
xi 1 xi
f ( x)dx
[ f ( xi ) 4 f ( xi 1 ) f ( xi 2 )]
3
i 1, 3, 5
n2
7- 23
• Proof of Simpson’s Rule
Using a second-order polynomial:
f ( x) kx2 hx l
7- 24
Passing through the three data points:
f ( a ) ka 2 ha l
f ( a x ) k ( a x ) 2 h( a x ) l
f (b) kb2 hb l
Integrating thesecond- order polynomial:
b
a
(kx 2 hx l )dx
k (b3 a 3 ) h (b 2 a 2 )
l (b a )
3
2
Then, we can obtain the Simpson’s formula.
7- 25
• The absolute value of the upper bound on
the error for the Simpson’s rule is estimated
by
4
( xi 1 xi )5 d f ( x j )
error
90
dx4
d 4 f (xj )
d 4 f ( x)
where
max
4
xi x xi 1
dx
dx4
7- 26
Example: Flow Rate Problem
• Applying Simpson’s rule to the data of Table.6
r0
Q V 2π rdr
0
2π ( 121 )
3
5
[V r 4V
r 1, 3
i i
r Vi 2 ri 2 ]
i 1 i 1
π
1
1
1
1
[10(0) 4(9.722)( ) 8.889( )] [8.889( ) 4(7.5)( )
18
12
6
6
4
1
1
5
1
5.556( )] [5.556( ) 4(3.056)( ) 0( )] 3.927 ft3 /sec
3
3
12
2
7- 27
Romberg Integration
• Denoting the trapezoidal estimate as I01
ba
I 01
( f (a ) f (b))
2
where a and b are the start and end of an interval.
• A second estimate I11:
ba 1
1
I11
( f (a ) f (m) f (b))
2 2
2
ab
ba
where m
a
2
2
1
ba
It can be rewritten : I11 [ I 01 (b a ) f (a
)]
2
2
7- 28
• A third estimate I21 can be obtained using three
equally spaced intermediate points m1, m2, and m3
ba 1
1
1
1
1
I 21
[ f (a) f (m1 ) f (m2 ) f (m3 ) f (b)]
2 4
2
2
2
4
and it can be rewritten as
3
1
ba
ba
I 21 I11
f
(
a
k )
2
2 k 1
4
k
2
7- 29
• Continuing this subdividing of the interval leads to
the following recursive relationship
1
b a 2 1
ba
I i1 I i 1,1 i 1 f (a i k ) for i 1, 2,...
2
2 k 1,3,5
2
i
• The general extrapolation formula in recursive
form is
I ij
4 j 1 I i 1, j 1 I i , j 1
4 j 1 1
7- 30
• The values of Iij can be presented in the following
upper-triangular matrix form:
I01
I02
I03
I04
…
I0,N-1
I0,N
I11
I12
I13
.
…
I1,N-1
I1,N
I21
I22
.
.
…
I2,N-1
I31
.
.
.
.
.
.
.
.
IN-2,3
.
IN-1,2
I0,N+1
IN1
7- 31
Example: Romberg Method for
Integration
• For the function f(u) = ueku, the integral is
ku
e
ku
ue
du k 2 (ku 1) c
• Let k = 2, we want to calculate
1
0
ue2 u du
The true value of the integral is 2.097264 (seven
significant digits).
7- 32
We have a=0, b=1.
For i 0
I 01 0.5(b a )( f ( a ) f (b))
0.5(1 0)(0 e 20 1 e 21 ) 3.69453
For i 1
ba
)]
2
0.5[3.69453 (1 0)(0.5 e 20.5 )] 2.52683
I11 0.5[ I 01 (b a ) f ( a
For i 2
ba
ba
I 21 0.5[ I11 0.5(b a )( f ( a
) f (a 3
))]
4
4
0.5[2.52683 0.5(0.25 e 20.25 0.75 e 20.75 )]
2.20678
7- 33
For i 3
ba
3(b a )
I 31 0.5[ I 21 0.25(b a )( f (a
) f (a
)
8
8
5(b a )
7(b a )
f (a
) f (a
))]
8
8
2.12478
For i 4
ba
3(b a )
I 41 0.5[ I 31 0.125(b a )( f ( a
) f (a
)
16
16
5(b a )
7( b a )
9( b a )
f (a
) f (a
) f (a
)
16
16
16
11(b a )
13(b a )
15(b a )
f (a
) f (a
) f (a
))]
16
16
16
2.10415
7- 34
Table.7 Computations According to the Romberg Method
i
j=1
2
3
4
5
6
0
3.69453
2.13760
2.09759
2.09727
2.09726
2.09726
1
2.52683
2.10009
2.09727
2.09726
2.09726
2
2.20678
2.09745
2.09726
2.09726
3
2.12478
2.09728
2.09726
4
2.10415
2.09727
5
2.09899
7- 35
• Similarly for i = 5, I51=2.09899
• I02 is computed as following:
421 (2.52683) 3.69453
I 02
2.13760
2 1
4 1
• I03 is computed as following:
431 (2.10009) 2.13760
I 03
2.09759
31
4 1
• The Romberg method yields an exact value to six
significant digits for the integral of 2.09726
7- 36