Top Banner
ES 240: Scientific and Engineering Computation. Cha Chapter 4: Errors Uchechukwu Ofoegbu Temple University
20

ES 240: Scientific and Engineering Computation. Chapter 4 Chapter 4: Errors Uchechukwu Ofoegbu Temple University.

Jan 12, 2016

Download

Documents

Bernice Cobb
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: ES 240: Scientific and Engineering Computation. Chapter 4 Chapter 4: Errors Uchechukwu Ofoegbu Temple University.

ES 240: Scientific and Engineering Computation. Chapter 4

Chapter 4: Errors

Uchechukwu Ofoegbu

Temple University

Page 2: 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.

Page 3: ES 240: Scientific and Engineering Computation. Chapter 4 Chapter 4: Errors Uchechukwu Ofoegbu Temple University.

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.

Page 4: ES 240: Scientific and Engineering Computation. Chapter 4 Chapter 4: Errors Uchechukwu Ofoegbu Temple University.

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

Page 5: ES 240: Scientific and Engineering Computation. Chapter 4 Chapter 4: Errors Uchechukwu Ofoegbu Temple University.

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

Page 6: ES 240: Scientific and Engineering Computation. Chapter 4 Chapter 4: Errors Uchechukwu Ofoegbu Temple University.

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

Page 7: ES 240: Scientific and Engineering Computation. Chapter 4 Chapter 4: Errors Uchechukwu Ofoegbu Temple University.

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

Page 8: ES 240: Scientific and Engineering Computation. Chapter 4 Chapter 4: Errors Uchechukwu Ofoegbu Temple University.

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.

Page 9: ES 240: Scientific and Engineering Computation. Chapter 4 Chapter 4: Errors Uchechukwu Ofoegbu Temple University.

ES 240: Scientific and Engineering Computation. Chapter 4

Roundoff Errors ExampleRoundoff Errors Example

Let’s try 4.8

Page 10: ES 240: Scientific and Engineering Computation. Chapter 4 Chapter 4: Errors Uchechukwu Ofoegbu Temple University.

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.

Page 11: ES 240: Scientific and Engineering Computation. Chapter 4 Chapter 4: Errors Uchechukwu Ofoegbu Temple University.

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

Page 12: ES 240: Scientific and Engineering Computation. Chapter 4 Chapter 4: Errors Uchechukwu Ofoegbu Temple University.

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.

Page 13: ES 240: Scientific and Engineering Computation. Chapter 4 Chapter 4: Errors Uchechukwu Ofoegbu Temple University.

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

Page 14: ES 240: Scientific and Engineering Computation. Chapter 4 Chapter 4: Errors Uchechukwu Ofoegbu Temple University.

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)

Page 15: ES 240: Scientific and Engineering Computation. Chapter 4 Chapter 4: Errors Uchechukwu Ofoegbu Temple University.

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)

Page 16: ES 240: Scientific and Engineering Computation. Chapter 4 Chapter 4: Errors Uchechukwu Ofoegbu Temple University.

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

Page 17: ES 240: Scientific and Engineering Computation. Chapter 4 Chapter 4: Errors Uchechukwu Ofoegbu Temple University.

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.

Page 18: ES 240: Scientific and Engineering Computation. Chapter 4 Chapter 4: Errors Uchechukwu Ofoegbu Temple University.

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.

Page 19: ES 240: Scientific and Engineering Computation. Chapter 4 Chapter 4: Errors Uchechukwu Ofoegbu Temple University.

ES 240: Scientific and Engineering Computation. Chapter 4

Taylor Series - LabTaylor Series - Lab

4.12

Page 20: ES 240: Scientific and Engineering Computation. Chapter 4 Chapter 4: Errors Uchechukwu Ofoegbu Temple University.

ES 240: Scientific and Engineering Computation. Chapter 4

HWHW

4.11, 15, 17,