Truncation Errors and The Taylor Series: Engr. Aure Flo A. Oraya, MSCE

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 29

Truncation Errors and

the Taylor Series


Engr. Aure Flo A. Oraya, MSCE
TRUNCATION ERRORSAND THE TAYLOR SERIES
Truncation Errors - result from using an approximation in place of an
exact mathematical procedure.

RECALL: Parachutist Problem


Approximation by Finite-Divided-Difference
Equation

TAYLOR SERIES – provides a means to predict a function value at one


point in terms of the function value and its derivative at another point
… any smooth function can be approximated as a polynomial…
ZERO-ORDER APPROXIMATION

TRUNCATION ERRORSAND THE TAYLOR SERIES


𝑓(𝑥𝑖+1 ) ≅ 𝑓(𝑥𝑖 ) The value of the new point is the
same as its value at the old point.
Assuming 𝑥𝑖 and 𝑥𝑖+1 are close to
each other.
The previous estimate is perfect if the function being approximated is
constant. If the function changes at all over the interval additional
terms are required to provide a better estimate.

FIRST-ORDER APPROXIMATION
Addt’l term includes
𝑓 𝑥𝑖+1 ≅ 𝑓 𝑥𝑖 + 𝑓′(𝑥𝑖 )(𝑥𝑖+1 − 𝑥𝑖 ) slope multiplied by the
distance
Though the change is already predicted in the preceding
approximation, this is only good for linear trend.
SECOND-ORDER APPROXIMATION

TRUNCATION ERRORSAND THE TAYLOR SERIES


𝑓 ′′ 𝑥𝑖
𝑓 𝑥𝑖+1 ≅ 𝑓 𝑥𝑖 + 𝑓 ′ 𝑥𝑖 𝑥𝑖+1 − 𝑥𝑖 + 𝑥𝑖+1 − 𝑥𝑖 2
2!
The second derivative captures the
curvature that the function might
exhibit.
Additional terms can be included to develop the complete Taylor series
expansion:

𝑓 ′′ 𝑥
𝑖
𝑓 𝑥𝑖+1 = 𝑓 𝑥𝑖 + 𝑓 ′ 𝑥𝑖 𝑥𝑖+1 − 𝑥𝑖 + 𝑥𝑖+1 − 𝑥𝑖 2
2!
𝑓 3 𝑥𝑖 3
𝑓 𝑛
𝑥𝑖
+ 𝑥𝑖+1 − 𝑥𝑖 + ⋯ + 𝑥𝑖+1 − 𝑥𝑖 𝑛 + 𝑅𝑛
3! 𝑛!

accounts for all terms from


n+1 to infinity
where the subscript n connotes that this is

TRUNCATION ERRORSAND THE TAYLOR SERIES


the remainder for the nth-order
approximation
and ξ is a value of x that lies somewhere
between 𝑥𝑖 and 𝑥𝑖+1 .

SIMPLIFIED FORM
TAYLOR’S THEOREM

TRUNCATION ERRORSAND THE TAYLOR SERIES


If the function 𝑓 and its first 𝑛 + 1 derivatives are
continuous on an interval containing 𝑎 and 𝑥, then the
value of the function at 𝑥 is given by
′′

𝑓 𝑎
𝑓 𝑥 =𝑓 𝑎 +𝑓 𝑎 𝑥−𝑎 + 𝑥−𝑎 2
2!
𝑓3 𝑎 3
𝑓 𝑛
𝑎
+ 𝑥 − 𝑎 + ⋯+ 𝑥 − 𝑎 𝑛 + 𝑅𝑛
3! 𝑛!
where the remainder 𝑅𝑛 is defined as
𝑥 𝑥−𝑡 𝑛 𝑛+1
𝑅𝑛 = 𝑎
𝑓 𝑡 𝑑𝑡 where t is a dummy variable.
𝑛!
Or integral form of the
𝑓𝜀 𝑛+1 remainder R
𝑛+1
𝑅𝑛 = 𝑥−𝑎 derivative form or
𝑛+1 ! Lagrange form of the
remainder R
EXAMPLE:

TRUNCATION ERRORSAND THE TAYLOR SERIES


Use zero-order through fourth-order Taylor series expansion to
approximate the function
𝑓 𝑥 = −0.1𝑥 4 − 0.15𝑥 3 − 0.5𝑥 2 − 0.25𝑥 + 1.2
from 𝑥𝑖 = 0 and ℎ = 1. That is, predict the functions value at
𝑥𝑖+1 = 1.

We are concerned with values between 𝑓(0) and 𝑓(1)


1.5

0.5
True Value
0
-1 -0.5 0 0.5 1 1.5 2

-0.5

-1

-1.5

-2
ZERO-ORDER APPROXIMATION

TRUNCATION ERRORSAND THE TAYLOR SERIES


𝑓 𝑥𝑖+1 ≅ 𝑓 𝑥𝑖
≅𝑓 0
≅ −0.1 0 4 − 0.15 0 3
− 0.5 0 2
− 0.25 0 + 1.2
≅ 1.2

FIRST-ORDER APPROXIMATION

𝑓 𝑥𝑖+1 ≅ 𝑓 𝑥𝑖 + 𝑓′(𝑥𝑖 )(𝑥𝑖+1 − 𝑥𝑖 )


𝑓 ′ 𝑥𝑖 = −0.4𝑥 3 − 0.45𝑥 2 − 𝑥 − 0.25
3 2
≅ 1.2 + [−0.4 0 − 0.45 0 − 0 − 0.25](1)
≅ 0.95
SECOND-ORDER APPROXIMATION

TRUNCATION ERRORSAND THE TAYLOR SERIES


𝑓 ′′ 𝑥𝑖
𝑓 𝑥𝑖+1 ≅ 𝑓 𝑥𝑖 + 𝑓 ′ 𝑥𝑖 𝑥𝑖+1 − 𝑥𝑖 + 𝑥𝑖+1 − 𝑥𝑖 2
2!
𝑓 ′ ′ 𝑥𝑖 = −1.2𝑥 2 − 1.35𝑥 − 1
3 2 2
−1.2 0 − 1.35 0 −1 1
𝑓 𝑥𝑖+1 ≅ 1.2 − 0.25 1 +
2!
𝑓 𝑥𝑖+1 ≅ 1.2 − 0.25 − 0.5 ≅ 0.45

THIRD-ORDER APPROXIMATION
𝑓 ′′ 𝑥𝑖
𝑓 𝑥𝑖+1 ≅ 𝑓 𝑥𝑖 + 𝑓 ′ 𝑥𝑖 𝑥𝑖+1 − 𝑥𝑖 + 𝑥𝑖+1 − 𝑥𝑖 2
2!
𝑓 3 𝑥𝑖
+ 𝑥𝑖+1 − 𝑥𝑖 3 𝑓 (3) 𝑥𝑖 = −2.4𝑥 − 0.9
3!
0.9 3
𝑓 𝑥𝑖+1 ≅ 1.2 − 0.25 − 0.5 − 1 ≅ 0.3
3!
FOURTH-ORDER APPROXIMATION

TRUNCATION ERRORSAND THE TAYLOR SERIES


𝑓 ′′ 𝑥
𝑖
𝑓 𝑥𝑖+1 ≅ 𝑓 𝑥𝑖 + 𝑓 ′ 𝑥𝑖 𝑥𝑖+1 − 𝑥𝑖 + 𝑥𝑖+1 − 𝑥𝑖 2
2!
𝑓 3 𝑥𝑖 𝑓 4 𝑥
𝑖
+ 𝑥𝑖+1 − 𝑥𝑖 3 + 𝑥𝑖+1 − 𝑥𝑖 4
3! 4!
𝑓 (4) 𝑥𝑖 = −2.4
0.9 3
2.4 4
𝑓 𝑥𝑖+1 ≅ 1.2 − 0.25 − 0.5 − 1 − 1 ≅ 0.2
3! 4!
Approximate Error
Value
Zero-Order 1.2 -1.0

TRUNCATION ERRORSAND THE TAYLOR SERIES


First-Order 0.95 -0.75
Second-Order 0.45 -.25
Third-Order 0.3 -0.1
Fourth-Order 0.2 0

Another
example is
presented in
the book. You
may refer to it.
(Page 86)
TRUNCATION ERRORSAND THE TAYLOR SERIES
In general, the nth-order Taylor series expansion will be
exact for an nth-order polynomial.

For other differentiable and continuous functions, such as


exponentials and sinusoids, a finite number of terms will not
yield an exact estimate. Each additional term will contribute
some improvement, however slight, to the approximation.

The assessment of how many terms are required to get “close enough” is based
on the remainder term of the expansion.

This relationship has two major drawbacks. First, ξ is not known exactly but
merely lies somewhere between 𝑥𝑖 and 𝑥𝑖+1 . Second, to evaluate the
remainder, we need to determine the (n +1)th derivative of f(x).
In general, we can usually assume that the truncation error is decreased by the
addition of terms to the Taylor series.
USING THE TAYLOR SERIES TO ESTIMATE
TRUNCATION ERRORS

TRUNCATION ERRORSAND THE TAYLOR SERIES


… using the falling parachutist example, we use the Taylor Series to
find the velocity as a function of time

If we truncate the series after the first derivative term, we have:

Or we can re-write this as first order approximation

truncation error
first order approximation

TRUNCATION ERRORSAND THE TAYLOR SERIES


truncation error

Recall this from our solution for the numerical solution of the falling
parachutist problem:

The difference is that using the Taylor Series, we now obtained an


estimate of the truncation error associated with this approximation
of the derivative. 𝑛+1 𝑓 𝜀 𝑛+1
𝑅𝑛 = 𝑥−𝑎
𝑣 1+1
𝜀 𝑣 ′′ 𝜀 𝑛+1 !
1+1 2
𝑅1 = 𝑡 − 𝑡𝑖 = 𝑡𝑖+1 − 𝑡𝑖
1 + 1 ! 𝑖+1 2!
𝑅1 𝑣 ′′ 𝜀
= 𝑡𝑖+1 − 𝑡𝑖 = 𝑂 𝑡𝑖+1 − 𝑡𝑖
𝑡𝑖+1 − 𝑡𝑖 2!
TRUNCATION ERRORSAND THE TAYLOR SERIES
If we want to approximate
the error, we can compute
for that using this formula
𝑅1 𝑣 ′′ 𝜀
= 𝑡𝑖+1 − 𝑡𝑖 = 𝑂 𝑡𝑖+1 − 𝑡𝑖
𝑡𝑖+1 − 𝑡𝑖 2!
NUMERICAL DIFFERENTIATION

TRUNCATION ERRORSAND THE TAYLOR SERIES


Earlier and in the last discussion we have already mentioned
Finite Divided Difference, like this

Generally, it can be represented as

Or

∆𝑓𝑖 is referred to as the first forward difference and ℎ is the step size
NUMERICAL DIFFERENTIATION

TRUNCATION ERRORSAND THE TAYLOR SERIES


Graphical Representation of Forward Finite-Divided-Difference
Approximations of the First Derivative
NUMERICAL DIFFERENTIATION

TRUNCATION ERRORSAND THE TAYLOR SERIES


Backward Finite-Divided-Difference Approximations of the First
Derivative

This can be obtained by expanding the Taylor Series backward to


calculate a previous value on the basis of the present value

Truncating the above equation after the first derivative will yield

where 𝛻𝑓𝑖 is referred to as the first backward difference


NUMERICAL DIFFERENTIATION

TRUNCATION ERRORSAND THE TAYLOR SERIES


Graphical Representation of Backward Finite-Divided-Difference
Approximations of the First Derivative
NUMERICAL DIFFERENTIATION

TRUNCATION ERRORSAND THE TAYLOR SERIES


Centered Finite-Divided-Difference Approximations of the First
Derivative

This can be obtained by subtracting 𝑓 𝑥𝑖−1 = 𝑓 𝑥𝑖 −


′ 𝑓′′ 𝑥𝑖
𝑓 𝑥𝑖 ℎ + ℎ2 − … from the Taylor Series to yield
2!

which can be solved for


EXAMPLE:

TRUNCATION ERRORSAND THE TAYLOR SERIES


Use forward and backward difference approximations of 𝑂 ℎ
and a centered difference approximation of 𝑂(ℎ2 ) to estimate
the derivative of
𝑓 𝑥 = −0.1𝑥 4 − 0.15𝑥 3 − 0.5𝑥 2 − 0.25𝑥 + 1.2
at 𝑥 = 0.5 using a step size ℎ = 0.5. Repeat the computation
using ℎ = 0.25. Note that the derivative can be calculated
directly as 𝑓 ′ 𝑥𝑖 = −0.4𝑥 3 − 0.45𝑥 2 − 𝑥 − 0.25 and can be
used to compute the true value of 𝑓 ′ 0.5 = −0.9125).

𝑓 𝑥𝑖 , 𝑓 𝑥𝑖+1
& 𝑓 𝑥𝑖−1
TRUNCATION ERRORSAND THE TAYLOR SERIES
For 𝒉 = 𝟎. 𝟓
𝑥𝑖−1 = 0.5 − ℎ = 0.5 − 0.5 = 0
𝑥𝑖 = 0.5
𝑥𝑖+1 = 0.5 + ℎ = 0.5 + 0.5 = 1

𝑓(𝑥𝑖−1 ) = 𝑓 0 = −0.1(0)4 −0.15(0)3 −0.5(0)2 −0.25(0) + 1.2


𝑓(𝑥𝑖−1 ) = 1.2
𝑓(𝑥𝑖 ) = 𝑓 0.5
= −0.1(0.5)4 −0.15(0.5)3 −0.5(0.5)2 −0.25(0.5) + 1.2
𝑓(𝑥𝑖 ) = 0.925
𝑓(𝑥𝑖+1 ) = 𝑓 1 = −0.1(1)4 −0.15(1)3 −0.5(1)2 −0.25(1) + 1.2
𝑓(𝑥𝑖+1 ) = 0.2

Forward Divided Difference



0.2 − 0.925 𝜀𝑡 = 58.9%
𝑓 0.5 = = −1.45
0.5
TRUNCATION ERRORSAND THE TAYLOR SERIES
For 𝒉 = 𝟎. 𝟓
𝑥𝑖−1 = 0.5 − ℎ = 0.5 − 0.5 = 0
𝑥𝑖 = 0.5
𝑥𝑖+1 = 0.5 + ℎ = 0.5 + 0.5 = 1

𝑓(𝑥𝑖−1 ) = 𝑓 0 = −0.1(0)4 −0.15(0)3 −0.5(0)2 −0.25(0) + 1.2


𝑓(𝑥𝑖−1 ) = 1.2
𝑓(𝑥𝑖 ) = 𝑓 0.5
= −0.1(0.5)4 −0.15(0.5)3 −0.5(0.5)2 −0.25(0.5) + 1.2
𝑓(𝑥𝑖 ) = 0.925
𝑓(𝑥𝑖+1 ) = 𝑓 1 = −0.1(1)4 −0.15(1)3 −0.5(1)2 −0.25(1) + 1.2
𝑓(𝑥𝑖+1 ) = 0.2

Backward Divided Difference



0.925 − 1.2 𝜀𝑡 = 39.7%
𝑓 0.5 = = −0.55
0.5
TRUNCATION ERRORSAND THE TAYLOR SERIES
For 𝒉 = 𝟎. 𝟓
𝑥𝑖−1 = 0.5 − ℎ = 0.5 − 0.5 = 0
𝑥𝑖 = 0.5
𝑥𝑖+1 = 0.5 + ℎ = 0.5 + 0.5 = 1

𝑓(𝑥𝑖−1 ) = 𝑓 0 = −0.1(0)4 −0.15(0)3 −0.5(0)2 −0.25(0) + 1.2


𝑓(𝑥𝑖−1 ) = 1.2
𝑓(𝑥𝑖 ) = 𝑓 0.5
= −0.1(0.5)4 −0.15(0.5)3 −0.5(0.5)2 −0.25(0.5) + 1.2
𝑓(𝑥𝑖 ) = 0.925
𝑓(𝑥𝑖+1 ) = 𝑓 1 = −0.1(1)4 −0.15(1)3 −0.5(1)2 −0.25(1) + 1.2
𝑓(𝑥𝑖+1 ) = 0.2

Center Divided Difference



0.2 − 1.2 𝜀𝑡 = 9.6%
𝑓 0.5 = = −1.0
1
TRUNCATION ERRORSAND THE TAYLOR SERIES
For 𝒉 = 𝟎. 𝟐𝟓
𝑥𝑖−1 = 0.5 − ℎ = 0.5 − 0.25 = 0.25
𝑥𝑖 = 0.5
𝑥𝑖+1 = 0.5 + ℎ = 0.5 + 0.25 = 0.75

𝑓(𝑥𝑖−1 ) = 𝑓 0.25
= −0.1(0.25)4 −0.15(0.25)3 −0.5(0)2 −0.25(0.25) + 1.2
𝑓(𝑥𝑖−1 ) = 1.10352
𝑓(𝑥𝑖 ) = 𝑓 0.5 = −0.1(0.5)4 −0.15(0.5)3 −0.5(0.5)2 −0.25(0.5) + 1.2
𝑓(𝑥𝑖 ) = 0.925
𝑓(𝑥𝑖+1 ) = 𝑓 0.75
= −0.1(0.75)4 −0.15(0.75)3 −0.5(1)2 −0.25(0.75) + 1.2
𝑓(𝑥𝑖+1 ) = 0.63633

Forward Divided Difference



0.63633 − 0.925 𝜀𝑡 = 26.5%
𝑓 0.5 = = −1.155
0.25
TRUNCATION ERRORSAND THE TAYLOR SERIES
For 𝒉 = 𝟎. 𝟐𝟓
𝑥𝑖−1 = 0.5 − ℎ = 0.5 − 0.25 = 0.25
𝑥𝑖 = 0.5
𝑥𝑖+1 = 0.5 + ℎ = 0.5 + 0.25 = 0.75

𝑓(𝑥𝑖−1 ) = 𝑓 0.25
= −0.1(0.25)4 −0.15(0.25)3 −0.5(0)2 −0.25(0.25) + 1.2
𝑓(𝑥𝑖−1 ) = 1.10352
𝑓(𝑥𝑖 ) = 𝑓 0.5 = −0.1(0.5)4 −0.15(0.5)3 −0.5(0.5)2 −0.25(0.5) + 1.2
𝑓(𝑥𝑖 ) = 0.925
𝑓(𝑥𝑖+1 ) = 𝑓 0.75
= −0.1(0.75)4 −0.15(0.75)3 −0.5(1)2 −0.25(0.75) + 1.2
𝑓(𝑥𝑖+1 ) = 0.63633

Backward Divided Difference



0.925 − 1.10352 𝜀𝑡 = 21.7%
𝑓 0.5 = = −0.714
0.25
TRUNCATION ERRORSAND THE TAYLOR SERIES
For 𝒉 = 𝟎. 𝟐𝟓
𝑥𝑖−1 = 0.5 − ℎ = 0.5 − 0.25 = 0.25
𝑥𝑖 = 0.5
𝑥𝑖+1 = 0.5 + ℎ = 0.5 + 0.25 = 0.75

𝑓(𝑥𝑖−1 ) = 𝑓 0.25
= −0.1(0.25)4 −0.15(0.25)3 −0.5(0)2 −0.25(0.25) + 1.2
𝑓(𝑥𝑖−1 ) = 1.10352
𝑓(𝑥𝑖 ) = 𝑓 0.5 = −0.1(0.5)4 −0.15(0.5)3 −0.5(0.5)2 −0.25(0.5) + 1.2
𝑓(𝑥𝑖 ) = 0.925
𝑓(𝑥𝑖+1 ) = 𝑓 0.75
= −0.1(0.75)4 −0.15(0.75)3 −0.5(1)2 −0.25(0.75) + 1.2
𝑓(𝑥𝑖+1 ) = 0.63633

Centered Divided Difference



0.63633 − 1.10352 𝜀𝑡 = 2.4%
𝑓 0.5 = = −0.934
0.5
TRUNCATION ERRORSAND THE TAYLOR SERIES
The centered difference approximation is more accurate than
the forward or backward differences.

Halving the step size approximately halves the error of the


backward and forward differences and quarters the error of the
centered difference.
Seatwork (Complete within
class hours)

You might also like