You are on page 1of 22

Sec:4.

Numerical
Differentiation
Sec:4.1 Numerical Differentiation Approximation

Forward-difference Formula Backward-difference Formula



𝑓 ( 𝒙 𝟎 +𝒉 ) − 𝑓 ( 𝒙 𝟎) h ′
𝑓 ( 𝒙 𝟎 ) − 𝑓 ( 𝒙 𝟎 − 𝒉) h
𝑓 ( 𝒙 𝟎 )= − 𝑓 ′ ′(𝜉 ) 𝑓 ( 𝒙 𝟎 )= + 𝑓 ′ ′(𝜉 )
h 2 h 2

where between and where between and


𝒙𝟎 𝒙 𝟎 +𝐡 𝒙𝟎 −𝐡 𝒙𝟎

Two-Point Formula
Example
Use table 4.2 and forward-difference formula to
approximate with
1
𝒉=𝟎. 𝟏 𝑓 ′ (2) ≈ { 𝑓 ( 2.1 ) − 𝑓 (2) }
(0.1)
Use table 4.2 and backward-difference formula to
approximate with

1
𝑓 ′ (2) ≈ { 𝑓 ( 2 ) − 𝑓 (1.8) }
𝒉=𝟎 . 𝟐 (0.2)
Sec:4.1 Numerical Differentiation Approximation

Three-Point Midpoint Formula Three-Point Endpoint Formula

𝒙 𝟎 −𝐡 𝒙𝟎 𝒙 𝟎 +𝐡 𝒙𝟎 𝒙 𝟎 +𝐡 𝒙𝟎 +𝟐 𝐡

Five-Point Midpoint Formula Five-Point Endpoint Formula

𝒙 𝟎 −𝟐 𝐡 𝒙𝟎 −𝐡 𝒙𝟎 𝒙 𝟎 +𝐡 𝒙𝟎 +𝟐 𝐡 𝒙𝟎 +𝟑 𝐡 𝒙 𝟎 +𝟒 𝐡
𝒙𝟎 𝒙 𝟎 +𝐡 𝒙𝟎 +𝟐 𝐡
Sec:4.1 Numerical Differentiation Approximation

Three-Point Midpoint Formula Three-Point Endpoint Formula

𝒙 𝟎 −𝐡 𝒙𝟎 𝒙 𝟎 +𝐡 𝒙𝟎 𝒙 𝟎 +𝐡 𝒙𝟎 +𝟐 𝐡

Example
Use table 4.2 and three-point endpoint formula to
approximate with

𝑓 ′ (2)≈

= 22.032310
Sec:4.1 Numerical Differentiation Approximation

Five-Point Midpoint Formula Five-Point Endpoint Formula

𝒙 𝟎 −𝟐 𝐡 𝒙𝟎 −𝐡 𝒙𝟎 𝒙 𝟎 +𝐡 𝒙𝟎 +𝟐 𝐡 𝒙𝟎 𝒙 𝟎 +𝐡 𝒙𝟎 +𝟐 𝐡 𝒙𝟎 +𝟑 𝐡 𝒙 𝟎 +𝟒 𝐡

Example
Use table 4.2 and five-point midpoint formula to
approximate with

𝑓 ′ (2) ≈

The only five-point formula for which the table


= 22.166999 gives sufficient data is the midpoint formula
Sec:4.1 Numerical Differentiation Approximation

Five-Point Midpoint Formula Five-Point Endpoint Formula

𝒙 𝟎 −𝟐 𝐡 𝒙𝟎 −𝐡 𝒙𝟎 𝒙 𝟎 +𝐡 𝒙𝟎 +𝟐 𝐡 𝒙𝟎 𝒙 𝟎 +𝐡 𝒙𝟎 +𝟐 𝐡 𝒙𝟎 +𝟑 𝐡 𝒙 𝟎 +𝟒 𝐡

Example
Use table 4.2 and five-point midpoint formula to
approximate with
𝑓 ′ (2) ≈ = 22.166999

Compute the actual error


The data given in Table 4.2 are taken from the function

The actual error =


Sec:4.1 Numerical Differentiation Approximation

Five-Point Midpoint Formula Five-Point Endpoint Formula

𝒙 𝟎 −𝟐 𝐡 𝒙𝟎 −𝐡 𝒙𝟎 𝒙 𝟎 +𝐡 𝒙𝟎 +𝟐 𝐡 𝒙𝟎 𝒙 𝟎 +𝐡 𝒙𝟎 +𝟐 𝐡 𝒙𝟎 +𝟑 𝐡 𝒙 𝟎 +𝟒 𝐡

Example
Use table 4.2 and five-point midpoint formula to
approximate with
𝑓 ′ (2) ≈ = 22.166999

Compute the actual error


The data given in Table 4.2 are taken from the function

The actual error =


Sec:4.1 Numerical Differentiation Approximation

Three-Point Midpoint Formula Three-Point Endpoint Formula

𝒙 𝟎 −𝐡 𝒙𝟎 𝒙 𝟎 +𝐡 𝒙𝟎 𝒙 𝟎 +𝐡 𝒙𝟎 +𝟐 𝐡

Example
Use table 4.2 and three-point midpoint formula to
approximate (consider all possible cases)

1
𝒉=𝟎. 𝟏 𝑓 ′ (2) ≈ { 𝑓 ( 2.1 ) − 𝑓 (1.9) }
2(0.1)
1
𝑓 ′ (2) ≈ { 𝑓 ( 2.2 ) − 𝑓 (1.8) }
𝒉=𝟎. 𝟐 2(0.2)
Sec:4.1 Numerical Differentiation Approximation

Three-Point Midpoint Formula Three-Point Endpoint Formula

𝒙 𝟎 −𝐡 𝒙𝟎 𝒙 𝟎 +𝐡 𝒙𝟎 𝒙 𝟎 +𝐡 𝒙𝟎 +𝟐 𝐡

Example
Use table 4.2 and three-point endpoint formula to
approximate (consider all possible cases)

𝒉=− 𝟎.𝟏
1
𝑓 ′ (2.2) ≈ { − 3 𝑓 ( 2.2 ) + 4 𝑓 ( 2.1 ) − 𝑓 (2)}
2(−0.1)
𝒉=− 𝟎.𝟐
1
𝑓 ′ (2.2)≈ { − 3 𝑓 ( 2.2 ) + 4 𝑓 ( 2 ) − 𝑓 (1.8) }
2(−0.2)
Sec:4.1 Numerical Differentiation Approximation

Three-Point Midpoint Formula Three-Point Endpoint Formula

𝒙 𝟎 −𝐡 𝒙𝟎 𝒙 𝟎 +𝐡 𝒙𝟎 𝒙 𝟎 +𝐡 𝒙𝟎 +𝟐 𝐡

Five-Point Midpoint Formula Five-Point Endpoint Formula

𝒙 𝟎 −𝟐 𝐡 𝒙𝟎 −𝐡 𝒙𝟎 𝒙 𝟎 +𝐡 𝒙𝟎 +𝟐 𝐡 𝒙𝟎 +𝟑 𝐡 𝒙 𝟎 +𝟒 𝐡
𝒙𝟎 𝒙 𝟎 +𝐡 𝒙𝟎 +𝟐 𝐡
Sec:4.1 Numerical Differentiation

Comparison Study
Example

  True Error
The true value 22.167168  
Three-point endpoint with h = 0.1 22.03231 e−1 × 1.35
Three-point endpoint with h = −0.1 22.054525 e−1 1.13
Three-point midpoint with h = 0.1 22.22879 e-2 6.16−
Three-point midpoint with h = 0.2 22.414163 e-1 2.47−
Five-point midpoint with h = 0.1 22.166999 e-4 1.69
Table 4.2 represents
values of
If we had no other information we would accept the five-point
midpoint approximation using h = 0.1 as the most accurate, and expect
the true value to be between that approximation and the three-point
mid-point approximation that is in the interval [22.166, 22.229].
Sec:4.1 Numerical Differentiation Approximation

Second Derivative Midpoint Formula

𝒙𝟎 −𝐡 𝒙𝟎 𝒙 𝟎 +𝐡

Example
Use table 4.2 and Second Derivative Midpoint Formula to approximate with

𝑓 ′ ′(2)≈ 𝑓 ′ ′(2)≈

= =
= 29.593200 = 29.704275

    True Error
The true value 29.556224  
midpoint with h = 0.1 29.5932 e-2 3.70−
midpoint with h = 0.2 29.704275 e-1 1.48−
Sec:4.1 Numerical Differentiation 𝑫𝒆𝒓𝒊𝒗𝒂𝒕𝒊𝒐𝒏𝒔
𝐿𝑎𝑔𝑟𝑎𝑛𝑔𝑒 𝐼𝑛𝑡𝑒𝑟𝑝𝑜𝑙𝑎𝑡𝑖𝑜𝑛 𝑝𝑜𝑙𝑦𝑛𝑜𝑚𝑖𝑎𝑙

𝑇𝑎𝑦𝑙𝑜𝑟 𝑠𝑒𝑟𝑖𝑒𝑠

Product of two functions


𝑫 𝒙 ( 𝒇𝒈 )=¿ 𝒇 ′ 𝒈 + 𝒇𝒈 ′
𝑫 𝒙 [ ( 𝒙 − 𝒙 𝟏 )( 𝒙 − 𝒙 𝟐 ) ]=¿ ( 𝒙 − 𝒙𝟐 ) +( 𝒙 − 𝒙𝟏 )

Product of three functions

𝑫 𝒙 ( 𝒇𝒈𝒌 )=¿ 𝒇 ′ 𝒈𝒌+𝒇 𝒈′ 𝒌+ 𝒇𝒈𝒌 ′

𝑫 𝒙 [ ( 𝒙 − 𝒙 𝟏 )( 𝒙 − 𝒙 𝟐 ) ( 𝒙 − 𝒙 𝟑 ) ] =¿
Sec:4.1 Numerical Differentiation 𝑫𝒆𝒓𝒊𝒗𝒂𝒕𝒊𝒐𝒏𝒔
Three-Point Midpoint Formula Three-Point Endpoint Formula

𝒙 𝟎 −𝐡 𝒙𝟎 𝒙 𝟎 +𝐡 𝒙𝟎 𝒙 𝟎 +𝐡 𝒙𝟎 +𝟐 𝐡

the second Lagrange polynomial

Differentiate both sides

= (+ +

Set
Sec:4.1 Numerical Differentiation

Three-Point Midpoint Formula Three-Point Endpoint Formula

𝒙 𝟎 −𝐡 𝒙𝟎 𝒙 𝟎 +𝐡 𝒙𝟎 𝒙 𝟎 +𝐡 𝒙𝟎 +𝟐 𝐡

the second Lagrange polynomial

Differentiate both sides

= (+ +

Set
Sec:4.1 Numerical Differentiation 𝑫𝒆𝒓𝒊𝒗𝒂𝒕𝒊𝒐𝒏𝒔

𝐿𝑎𝑔𝑟𝑎𝑛𝑔𝑒 𝐼𝑛𝑡𝑒𝑟𝑝𝑜𝑙𝑎𝑡𝑖𝑜𝑛 𝑝𝑜𝑙𝑦𝑛𝑜𝑚𝑖𝑎𝑙

𝑇𝑎𝑦𝑙𝑜𝑟 𝑠𝑒𝑟𝑖𝑒𝑠

Use Lagrange polynomial and the


given nodes to express as then
differentiate both sides. Next set
Sec:4.1 Numerical Differentiation

𝑻𝒂𝒚𝒍𝒐𝒓 𝒔𝒆𝒓𝒊𝒆𝒔
1 2 1 3 1 4
𝑓 ( 𝑥 0 +𝑘 )= 𝑓 ( 𝑥 0 ) +𝑘𝑓 ′ ( 𝑥 0 ) + 𝑘 𝑓 ′ ′ ( 𝑥0 )+ 𝑘 𝑓 ′ ′ ′ ( 𝑥 0 )+ 𝑘 𝑓 ′ ′ ′ ′ ( 𝑥 0 )+ ⋯
2 6 24

𝒔𝒆𝒕 𝒌=𝒉
1 2 1 3 1 4
𝑓 ( 𝑥 0 +h ) = 𝑓 ( 𝑥0 ) + h𝑓 ′ ( 𝑥0 ) + h 𝑓 ′ ′ ( 𝑥 0 ) + h 𝑓 ′ ′ ′ ( 𝑥 0 ) + h 𝑓 ′ ′ ′ ′ ( 𝑥0 ) + ⋯
2 6 24

𝒔𝒆𝒕 𝒌=𝟐 𝒉
2 4 3 4 4
𝑓 ( 𝑥 0 +2 h ) = 𝑓 ( 𝑥 0 ) +2 h𝑓 ′ ( 𝑥 0 ) +2 h 𝑓 ′ ′ ( 𝑥0 )+ h 𝑓 ′ ′ ′ ( 𝑥 0 ) + h 𝑓 ′ ′ ′ ′ ( 𝑥 0 ) +⋯
3 3

𝒔𝒆𝒕 𝒌=−𝒉
1 2 1 3 1 4
𝑓 ( 𝑥 0 −h )= 𝑓 ( 𝑥0 ) − h 𝑓 ′ ( 𝑥 0 ) + h 𝑓 ′ ′ ( 𝑥 0 ) − h 𝑓 ′ ′ ′ ( 𝑥 0 ) + h 𝑓 ′ ′ ′ ′ ( 𝑥0 ) + ⋯
2 6 24

𝒔𝒆𝒕 𝒌=−𝟐 𝒉
4 3 4
𝑓 ( 𝑥 0 −2 h ) = 𝑓 ( 𝑥 0 ) −2 h𝑓 ′ ( 𝑥 0 ) +2 h2 𝑓 ′ ′ ( 𝑥 0 ) − h 𝑓 ′ ′ ′ (𝑥0 )+ h4 𝑓 ′ ′ ′ ′ (𝑥0 )+ ⋯
3 3
Sec:4.1 Numerical Differentiation
Example
Derive a three-point formula to approximate f’(x0) that uses f (x0), f (x0 + h), f (x0 +
2h). Then find the error term [what is the order of the error O(

𝒇 ′ ( 𝒙 𝟎 )= 𝑨 𝒇 ( 𝒙 𝟎 ) + 𝑩 𝒇 ( 𝒙 𝟎 + 𝒉 ) + 𝑪 𝒇 ( 𝒙 𝟎 +𝟐 𝒉 ) + 𝑬𝒓𝒓𝒐𝒓

𝑨 𝑓 ( 𝑥0)= 𝑓 ( 𝑥0)

𝑩 ′
𝑓 ( 𝑥 0 +h ) = 𝑓 ( 𝑥0 ) + h 𝑓 ( 𝑥0 )+
1 2 ′′
2
1 3 ′′ ′
h 𝑓 ( 𝑥 0 ) + h 𝑓 ( 𝑥 0 ) +⋯
6

𝑪 4
𝑓 ( 𝑥 0 +2 h ) = 𝑓 ( 𝑥 0 ) +2 h 𝑓 ′ ( 𝑥 0 ) +2 h2 𝑓 ′ ′ ( 𝑥0 )+ h3 𝑓 ′ ′ ′ ( 𝑥 0 ) + ⋯
3

¿
( 𝐴+ 𝐵 + 𝐶 ) 𝑓 ( 𝑥0 ) + h ( 𝐵 +2 𝐶 ) 𝑓 ′ ( 𝑥 0 ) +h

3
2
( 1
2 )
𝐵+2 𝐶 𝑓 ′ ′ ( 𝑥 0 )
1 4
+( 𝐵𝑓 ′ ′ ′ ( 𝑥 0 ) + 𝐶𝑓 ′ ′ ′ ( 𝑥0 ))h
6 3

We have 3 constants to determine (A, B, C). So we need three equations


( 𝐴+ 𝐵+ 𝐶 )=0 −𝟑 𝟐 −𝟏

h ( 𝐵+2 𝐶 )=1
h
1
2
2 (
𝐵+2 𝐶 =0 ) ′
𝑨=

𝒇 ( 𝒙 𝟎 )≈ −
𝟐𝒉
𝟑
𝟐𝒉
𝑩=
𝟐
𝒉
𝑪=

𝒇 ( 𝒙 𝟎 ) + 𝒇 ( 𝒙 𝟎+ 𝒉 ) −
𝒉
𝟐𝒉
𝟏
𝟐𝒉
𝒇 ( 𝒙 𝟎 +𝟐 𝒉 )
Sec:4.1 Numerical Differentiation
Example
Derive a three-point formula to approximate f’(x0) that uses f (x0), f (x0 + h), f (x0 +
2h). Then find the error term [what is the order of the error O(

𝒇 ′ ( 𝒙 𝟎 )= 𝑨 𝒇 ( 𝒙 𝟎 ) + 𝑩 𝒇 ( 𝒙 𝟎 + 𝒉 ) + 𝑪 𝒇 ( 𝒙 𝟎 +𝟐 𝒉 ) + 𝑬𝒓𝒓𝒐𝒓

𝑨 𝑓 ( 𝑥0)= 𝑓 ( 𝑥0)

𝑩 𝑓 ( 𝑥 0 +h ) = 𝑓 ( 𝑥0 ) + h 𝑓 ( 𝑥0 )+
1 2 ′′
2
′ 1 3 ′′ ′
h 𝑓 ( 𝑥 0 ) + h 𝑓 ( 𝑥 0 ) +⋯
6
𝑪 ′ 2 ′′ 4 3 ′′ ′
𝑓 ( 𝑥 0 +2 h ) = 𝑓 ( 𝑥 0 ) +2 h 𝑓 ( 𝑥 0 ) +2 h 𝑓 ( 𝑥0 )+ h 𝑓 ( 𝑥 0 ) + ⋯
3

¿
( 𝐴+ 𝐵 + 𝐶 ) 𝑓 ( 𝑥0 ) + h ( 𝐵 +2 𝐶 ) 𝑓 ′ ( 𝑥 0 ) +h

3
2
( 1
2 )
𝐵+2 𝐶 𝑓 ′ ′ ( 𝑥 0 )
1 4
+( 𝐵𝑓 ′ ′ ′ ( 𝑥 0 ) + 𝐶𝑓 ′ ′ ′ ( 𝑥0 ))h
6 3

find the error term ′


𝒇 ( 𝒙 𝟎 )≈ −
𝟑 𝟐
𝒇 ( 𝒙 𝟎 ) + 𝒇 ( 𝒙 𝟎+ 𝒉 ) −
𝟏
𝒇 ( 𝒙𝟎 +𝟐 𝒉 ) −𝟑 𝟐 −𝟏
𝟐𝒉 𝒉 𝟐𝒉 𝑨= 𝑩= 𝑪=
𝟐𝒉 𝒉 𝟐𝒉
3
Leading 1 4 𝟏 ′′ ′ 𝟐 𝟑
𝟏 𝟐
𝟐
¿( 𝐵𝑓 ′ ′ ′ ( 𝑥 0 )+ 𝐶𝑓 ′ ′ ′ ( 𝑥0 ) ) h 𝟑 𝒉
¿( 𝒇 ( 𝒙 𝟎 ) −
𝟑𝒉
𝒇 ′ ′ ′ ( 𝒙 𝟎 ) )𝒉 ¿ − 𝒇 ′ ′ ′ ( 𝒙 𝟎) 𝒉 𝑬𝒓𝒓𝒐𝒓 =𝑶(𝒉 )
error term 6 3 𝟑
𝟐
′ 𝟑 𝟐 𝟏 𝟏
𝒇 ( 𝒙 𝟎 )=− 𝒇 ( 𝒙 𝟎 ) + 𝒇 ( 𝒙 𝟎+ 𝒉) − 𝒇 ( 𝒙 𝟎 +𝟐 𝒉) − 𝒇 ′ ′ ′ ( 𝝃 ) 𝒉
𝟐𝒉 𝒉 𝟐𝒉 𝟑
Sec:4.1 Numerical Differentiation
Example
Derive a three-point formula to approximate f’’(x0) that uses f (x0), f (x0 + h), f (x0 +
2h).

𝒇 ′ ′ ( 𝒙 𝟎 ) = 𝑨 𝒇 ( 𝒙 𝟎 ) + 𝑩 𝒇 ( 𝒙 𝟎+𝒉 ) + 𝑪 𝒇 ( 𝒙 𝟎 +𝟐 𝒉 ) + 𝑬𝒓𝒓𝒐𝒓

𝑨 𝑓 ( 𝑥0)= 𝑓 ( 𝑥0)

𝑩 ′
𝑓 ( 𝑥 0 +h ) = 𝑓 ( 𝑥0 ) + h 𝑓 ( 𝑥0 )+
1 2 ′′
2
1 3 ′′ ′
h 𝑓 ( 𝑥 0 ) + h 𝑓 ( 𝑥 0 ) +⋯
6

𝑪 4
𝑓 ( 𝑥 0 +2 h ) = 𝑓 ( 𝑥 0 ) +2 h 𝑓 ′ ( 𝑥 0 ) +2 h2 𝑓 ′ ′ ( 𝑥0 )+ h3 𝑓 ′ ′ ′ ( 𝑥 0 ) + ⋯
3

¿
( 𝐴+ 𝐵 + 𝐶 ) 𝑓 ( 𝑥0 ) + h ( 𝐵 +2 𝐶 ) 𝑓 ′ ( 𝑥 0 ) +h

3
2
( 1
2 )
′′
𝐵+2 𝐶 𝑓 ( 𝑥 0 )
1 4
+( 𝐵𝑓 ′ ′ ′ ( 𝑥 0 ) + 𝐶𝑓 ′ ′ ′ ( 𝑥0 ))h
6 3

We have 3 constants to determine (A, B, C). So we need three equations


( 𝐴+ 𝐵+ 𝐶 )=0
h ( 𝐵+2 𝐶 )=𝟎
h2 ( 1
2
𝐵+2 𝐶 =𝟏 )
Sec:4.1 Numerical Differentiation

𝑓 ′ ( 𝑥 0 )= 𝑨 𝑓 ( 𝑥 0 − h ) + 𝑩 𝑓 ( 𝑥 0 ) + 𝑪 𝑓 ( 𝑥 0 +h )+ 𝑫 𝑓 ( 𝑥 0 +2 h ) + 𝑬 𝑓 ( 𝑥 0 +3 h ) + 𝑬𝒓𝒓𝒐𝒓

1 2 1 3 1 4
𝑨 𝑓 ( 𝑥 0 −h )= 𝑓 ( 𝑥0 ) − h 𝑓 ′ ( 𝑥 0 ) + h 𝑓 ′ ′ ( 𝑥 0 ) − h 𝑓 ′ ′ ′ ( 𝑥 0 ) +
2 6 24
h 𝑓 ′ ′ ′ ′ ( 𝑥0 ) + ⋯

𝑩 𝑓 ( 𝑥0)= 𝑓 ( 𝑥0)

1 2 1 3 1 4
𝑪 𝑓 ( 𝑥 0 +h ) = 𝑓 ( 𝑥0 ) + h𝑓 ′ ( 𝑥0 ) +
2
h 𝑓 ′ ′ ( 𝑥0)+ h 𝑓 ′ ′ ′ ( 𝑥0)+
6 24
h 𝑓 ′ ′ ′ ′ ( 𝑥0 ) + ⋯

4 3 4 4
𝑫
2
𝑓 ( 𝑥 0 +2 h ) = 𝑓 ( 𝑥 0 ) +2 h𝑓 ′ ( 𝑥 0 ) +2 h 𝑓 ′ ′ ( 𝑥0 )+ h 𝑓 ′ ′ ′ ( 𝑥 0 ) + h 𝑓 ′ ′ ′ ′ ( 𝑥 0 ) +⋯
3 3

𝑬 2
𝑓 ( 𝑥 0 +2 h ) = 𝑓 ( 𝑥 0 ) +2 h𝑓 ′ ( 𝑥 0 ) +2 h 𝑓 ′ ′ ( 𝑥0 )+
4 3
3
4 4
h 𝑓 ′ ′ ′ ( 𝑥 0 ) + h 𝑓 ′ ′ ′ ′ ( 𝑥 0 ) +⋯
3

𝑳𝑯𝑺=¿
Sec:4.1 Numerical Differentiation

You might also like