ES 240: Scientific and Engineering Computation. Cha Chapter 4: Errors Uchechukwu Ofoegbu Temple University
ES 240: Scientific and Engineering Computation. Chapter 4
Chapter 4: Errors
Uchechukwu Ofoegbu
Temple University
ES 240: Scientific and Engineering Computation. Chapter 4
Murphy's Laws of Computing
1. When computing, whatever happens, behave as though you meant it to happen.
2. For every action, there is an equal and opposite malfunction.
3. To err is human... to blame your computer for your mistakes is even more than human--it's downright natural.
4. He who laughs last probably made a backup.
5. If at first you don't succeed, blame your computer.
6. The number one cause of computer problems is computer solutions.
7. A computer program will always do what you tell it to do, but rarely what you want to do.
ES 240: Scientific and Engineering Computation. Chapter 4
Accuracy and PrecisionAccuracy and Precision
Accuracy– how closely a computed or measured value agrees with
the true value
Precision – how closely individual computed or measured values
agree with each other.
ES 240: Scientific and Engineering Computation. Chapter 4
Error DefinitionsError Definitions
True error:– Et = True Value - Approximation
Absolute error:– |Et|
True fractional relative error:–
Relative error–
ValueTrue
Et
_
%100_ValueTrue
Ett
ES 240: Scientific and Engineering Computation. Chapter 4
Error ApproximationError Approximation
The approximate percent relative error
–
For iterative processes, the error can be approximated as the difference in values between successive iterations.
%100_
_
valuetrue
errorionapproximata
%100_
__
ionapproximatpresent
ionapproximatpreviousionapproximatpresenta
ES 240: Scientific and Engineering Computation. Chapter 4
Using Error EstimatesUsing Error Estimates
Stopping Criterion– The sign of the error is not the problem– We just want the error to be less than a specific value
– The computation is repeated until | a |< s
Correct to at least n significant figures– set )%105.0( 2 n
s
ES 240: Scientific and Engineering Computation. Chapter 4
Error Estimates - ExampleError Estimates - Example
Write an m-file that – approximates cos(x) using 1-10 terms– plots the relative error versus the number of terms
Determine the stopping criterion that will ensure that the cosine approximation is correct to at least 5 significant figures
Write an m-file that will– Approximate cos(x) correctly up to 10 significant figures. – Display the approximation until it stops– Be creative – Display the number of terms it took
ES 240: Scientific and Engineering Computation. Chapter 4
Roundoff ErrorsRoundoff Errors
Roundoff errors arise because digital computers cannot represent some quantities exactly.
There are two major facets of roundoff errors involved in numerical calculations:– Digital computers can only represent numbers up to a
certain size and precision, so they round-off.– Some numerical manipulations are easily affected by the
roundoff errors.
ES 240: Scientific and Engineering Computation. Chapter 4
Roundoff Errors ExampleRoundoff Errors Example
Let’s try 4.8
ES 240: Scientific and Engineering Computation. Chapter 4
The Taylor Theorem and SeriesThe Taylor Theorem and Series
The Taylor theorem states that any smooth function can be approximated as a polynomial.
The Taylor series provides a means to express this idea mathematically.
ES 240: Scientific and Engineering Computation. Chapter 4
The Taylor SeriesThe Taylor Series
f x i1 f x i f ' x i h f '' x i 2!
h2 f (3) x i 3!
h3 f (n ) x i
n!hn Rn
Step SizeStep Size
ES 240: Scientific and Engineering Computation. Chapter 4
Truncation ErrorTruncation Error
In general, the nth order Taylor series expansion will be exact for an nth order polynomial.
In other cases, the remainder term Rn is of the order of hn+1, meaning:– The more terms are used, the smaller the error, and– The smaller the spacing, the smaller the error for a given
number of terms.
ES 240: Scientific and Engineering Computation. Chapter 4
Taylor Series - ExampleTaylor Series - Example
In Matlab: – Use Taylor Series for n = 0-5 to Evaluate f(x) = sin x, at xi+1 = π
on the basis of f(x) and its derivatives at π/2. – Display the truncation error as n increases– Vary h and observe the difference
ES 240: Scientific and Engineering Computation. Chapter 4
Numerical DifferentiationNumerical Differentiation
The first order Taylor series can be used to calculate approximations to derivatives:– Given:
– Then:
This is termed a “forward” difference because it utilizes data at i and i+1 to estimate the derivative.
f (x i1) f (x i) f '(x i)h O(h2)
f '(x i)f (x i1) f (x i)
h O(h)
ES 240: Scientific and Engineering Computation. Chapter 4
Differentiation (cont)Differentiation (cont)
There are also backward difference and centered difference approximations, depending on the points used:
Forward:
Backward:
Centered:
f '(x i)f (x i1) f (x i)
h O(h)
f '(x i)f (x i) f (x i 1)
h O(h)
f '(x i)f (x i1) f (x i 1)
2h O(h2)
ES 240: Scientific and Engineering Computation. Chapter 4
ExampleExample
234 2.03.0)( xxxxf
xxxxf 26.02.1)(' 23
x = 0.5; h = 0.5
ES 240: Scientific and Engineering Computation. Chapter 4
Total Numerical ErrorTotal Numerical Error
The total numerical error is the summation of the truncation and roundoff errors.
The truncation error generally increases as the step size increases, while the roundoff error decreases as the step size increases - this leads to a point of diminishing returns for step size.
ES 240: Scientific and Engineering Computation. Chapter 4
Other ErrorsOther Errors
Blunders - errors caused by malfunctions of the computer or human imperfection.
Model errors - errors resulting from incomplete mathematical models.
Data uncertainty - errors resulting from the accuracy and/or precision of the data.
ES 240: Scientific and Engineering Computation. Chapter 4
Taylor Series - LabTaylor Series - Lab
4.12
ES 240: Scientific and Engineering Computation. Chapter 4
HWHW
4.11, 15, 17,