Docsity

Scientific Computing - Lecture Slides | CS 4803, Study notes of Computer Science

Partial preview of the text

Download Scientific Computing - Lecture Slides | CS 4803 and more Study notes Computer Science in PDF only on Docsity!

Approximations Computer Arithmetic Mathematical Software

Scientific Computing: An Introductory Survey

Chapter 1 – Scientific Computing

Prof. Michael T. Heath

Department of Computer Science

University of Illinois at Urbana-Champaign

Copyright c© 2002. Reproduction permitted

for noncommercial, educational use only.

Approximations Computer Arithmetic Mathematical Software

Outline

(^1) Introduction

(^2) Approximations

(^3) Computer Arithmetic

(^4) Mathematical Software

Approximations Computer Arithmetic Mathematical Software

Well-Posed Problems

Problem is well-posed if solution

exists

is unique

depends continuously on problem data

Otherwise, problem is ill-posed

Even if problem is well posed, solution may still be

sensitive to input data

Computational algorithm should not make sensitivity worse

Approximations Computer Arithmetic Mathematical Software

General Strategy

Replace difficult problem by easier one having same or

closely related solution

infinite → finite

differential → algebraic

nonlinear → linear

complicated → simple

Solution obtained may only approximate that of original

problem

Approximations Computer Arithmetic Mathematical Software

Example: Approximations

Computing surface area of Earth using formula A = 4πr

2

involves several approximations

Earth is modeled as sphere, idealizing its true shape

Value for radius is based on empirical measurements and

previous computations

Value for π requires truncating infinite process

Values for input data and results of arithmetic operations

are rounded in computer

Approximations Computer Arithmetic Mathematical Software

Absolute Error and Relative Error

Absolute error : approximate value − true value

Relative error : (absolute error) / (true value)

Equivalently, approx value = (true value) × (1 + rel error)

True value usually unknown, so we estimate or bound

error rather than compute it exactly

Relative error often taken relative to approximate value,

rather than (unknown) true value

Approximations Computer Arithmetic Mathematical Software

Truncation Error and Rounding Error

Truncation error : difference between true result (for actual

input) and result produced by given algorithm using exact

arithmetic

Due to approximations such as truncating infinite series or

terminating iterative sequence before convergence

Rounding error : difference between result produced by

given algorithm using exact arithmetic and result produced

by same algorithm using limited precision arithmetic

Due to inexact representation of real numbers and

arithmetic operations upon them

Computational error is sum of truncation error and

rounding error, but one of these usually dominates

Approximations Computer Arithmetic Mathematical Software

Example: Finite Difference Approximation

Error in finite difference approximation

f

′ (x) ≈

f (x + h) − f (x)

h

exhibits tradeoff between rounding error and truncation

error

Truncation error bounded by M h/ 2 , where M bounds

|f

′′ (t)| for t near x

Rounding error bounded by 2 /h, where error in function

values bounded by 

Total error minimized when h ≈ 2

/M

Error increases for smaller h because of rounding error

and increases for larger h because of truncation error

Approximations Computer Arithmetic Mathematical Software

Forward and Backward Error

Suppose we want to compute y = f (x), where f : R → R,

but obtain approximate value yˆ

Forward error : ∆y = ˆy − y

Backward error : ∆x = ˆx − x, where f (ˆx) = ˆy

Approximations Computer Arithmetic Mathematical Software

Example: Forward and Backward Error

As approximation to y =

2 , yˆ = 1. 4 has absolute forward

error

|∆y| = |yˆ − y| = | 1. 4 − 1. 41421... | ≈ 0. 0142

or relative forward error of about 1 percent

Since

1 .96 = 1. 4 , absolute backward error is

|∆x| = |xˆ − x| = | 1. 96 − 2 | = 0. 04

or relative backward error of 2 percent

Approximations Computer Arithmetic Mathematical Software

Example: Backward Error Analysis

Approximating cosine function f (x) = cos(x) by truncating

Taylor series after two terms gives

y ˆ =

f (x) = 1 − x

2 / 2

Forward error is given by

∆y = ˆy − y =

f (x) − f (x) = 1 − x

2 / 2 − cos(x)

To determine backward error, need value xˆ such that

f (ˆx) =

f (x)

For cosine function, xˆ = arccos(

f (x)) = arccos(ˆy)

Approximations Computer Arithmetic Mathematical Software

Example, continued

For x = 1,

y = f (1) = cos(1) ≈ 0. 5403

yˆ =

f (1) = 1 − 1

2 /2 = 0. 5

ˆx = arccos(ˆy) = arccos(0.5) ≈ 1. 0472

Forward error: ∆y = ˆy − y ≈ 0. 5 − 0 .5403 = − 0. 0403

Backward error: ∆x = ˆx − x ≈ 1. 0472 − 1 = 0. 0472

Approximations Computer Arithmetic Mathematical Software

Condition Number

Condition number is amplification factor relating relative

forward error to relative backward error

relative

forward error

= cond ×

relative

backward error

Condition number usually is not known exactly and may

vary with input, so rough estimate or upper bound is used

for cond, yielding

relative

forward error

/ cond ×

relative

backward error

Approximations Computer Arithmetic Mathematical Software

Example: Evaluating Function

Evaluating function f for approximate input xˆ = x + ∆x

instead of true input x gives

Absolute forward error: f (x + ∆x) − f (x) ≈ f

′ (x)∆x

Relative forward error:

f (x + ∆x) − f (x)

f (x)

f

′ (x)∆x

f (x)

Condition number: cond ≈

f

′ (x)∆x/f (x)

∆x/x

xf

′ (x)

f (x)

Relative error in function value can be much larger or

smaller than that in input, depending on particular f and x