• Tidak ada hasil yang ditemukan

Chapter 19 Numerics in General in General

N/A
N/A
Protected

Academic year: 2023

Membagikan "Chapter 19 Numerics in General in General"

Copied!
123
0
0

Teks penuh

(1)

Chapter 19 Chapter 19 Chapter 19 Chapter 19 Numerics

Numerics in General in General

Bo-Yeong Kang, 2009

Kyungpook National University

1

(2)

What is What is

numerical analysis ? y

(3)

The study of algorithms to sol e the problems that

solve the problems that

there is no solution formula

3

(4)

19.1 Introduction

The steps from problems p p to answer

Modeling Modeling

Choosing a numeric methods programming

programming

Doing the computation

Interpreting the results

(5)

19.1 Introduction

Real number

Fl ti i t f f Floating point form of

numbers numbers

0.6247*10

3

, 0.735*10

-13

, -0.2000*

10-1

Number of significant digits is kept fixed g g p Decimal point “floating”

5

(6)

19.1 Introduction

Floating point form of Floating point form of numbers

numbers

a = m*10

n

, 0.1≤|m| < 1

On computers, m & n is limited p ,

ā = m*10

n

, m=0.d

1

d

2

…d

k

, d

1

>0

mantissa

exponent mantissa

(7)

19.1 Introduction

Floating point form of n mbe s

numbers

ā = m*10

n

, m=0.d

1

d

2

…d

k

, d

1

>0

mantissa

exponent exponent

sign mantissati

IBM 3000 & 4000 series Single precision floating point number 1 sign, 7 exponent, 24 mantissa, 32 bits

7

(8)

19.1 Introduction

Floating point form of oat g po t o o numbers

The number outside that range occurs

Underflow when the number is smaller (zero) Overflow when it is larger (halt)

exponent

sign mantissa

(9)

19.1 Introduction

Roundoff(

끝처리

)

mantissa

Roundoff(

끝처리

)

0.d

1

d

2

…d

k

d

k+1

d

k +2

d

k+3

Roundoff rule

Discard (k+1)th and all subsequent decimals

Discard (k+1)th and all subsequent decimals

If the number discarded is less than half a unit in kth place, leave kth decimal unchanged(rounding down)

If it is greater than half a unit, round add one to the kth decimal If it is greater than half a unit, round add one to the kth decimal (rounding up)

If it is exactly half a unit, round off to the nearest even decimal

Rounding up/down happens about equallyg p/ pp q y ex)3.45-3.4, 3.55-3.6

9

(10)

19.1 Introduction

Error in Rounding Error in Rounding

ā= fl(a),

floating point approximation of a by rounding

|m-m| ≤ ½ * 10

-k (ex. |0.45-0.4| ≤ ½ * 10-1)

|m| ≥ 0.1 , 1/|m| ≤ 10

|(a- ā)/a| ≈|(m-m)/m| ≤ ½ * 10

1-k

Error bound in rounding

(11)

19.1 Introduction

Errors of Numeric Results

Finding the results – Approximation

Rounding errors

Experimental errors from measurements

T ncating e o s f om p emat el b eaking off Truncating errors from prematurely breaking off

Formulas for Errors Formulas for Errors

є = a – ã

a = ã + є , True value = Approximation + error a ã + є , True value Approximation + error ã = 10.5, a=10.2, є = -0.3

11

(12)

19.1 Introduction

Errors of Numeric Results

є = |a – ã|(absolute error) or ã – a | |( )

є

r

= є/a = (a-ã)/a = Error/True value (relative error ) This look useless because a is unknown

/ã є

r

= є/ã

This still looks problematic because є is unknown

One can obtain in practice is an error bound for ã, 

|є| ≤  , hence |a-ã| ≤ 

| |  | | 

r

|≤ 

r

, hence |(a-ã)/a| ≤ 

r

(13)

19.1 Introduction

E P ti

Error Propagation

How errors at the beginning and in later steps

propagate into the computation and affect accuracy (a) Subtraction

x = x+ є y=ỹ+є |є | ≤  |є | ≤ 

x = x+ є

1

, y=ỹ+є

2

, |є

1

| ≤ 

1 ,

2

| ≤ 

2

є = |x-y – (x-ỹ)|

= |x-x – (y-ỹ)|

True value subtraction

Approximation subtraction

= |x x (y ỹ)|

= | є

1

– є

2

| ≤ |є

1

|+|є

2

| ≤ 

1

+ 

2

13

(14)

19.1 Introduction

Error Propagation Error Propagation

(b) Relative error of multiplication

x = x+ є

1

, y=ỹ+ є

2

, |є

r1

| ≤ 

r1 ,

r2

| ≤ 

r2

|( ỹ)/ | є

r

= |(xy – xỹ)/xy|

= |(xy – (x- є

1

)(y-є

2

))/xy|

|( )/ |

= |(є

1

y+є

2

y-є

1

є

2

)/xy|

≈ |(є

1

y+є

2

x)/xy|

| / | | / | | | | |

≤ | є

1

/x |+ |є

2

/y| = |є

r1

|+|є

r2

| ≤ 

r1

+ 

r2

(15)

19.1 Introduction

Error Propagation Error Propagation

Th 1 E P i

Th 1 E P i

Th.1 Error Propagation Th.1 Error Propagation

(a)In addition and subtraction, an error bound

f th lt i i b th f th

for the results is given by the sum of the error bounds for the terms

(b)I lti li ti d di i i b d

(b)In multiplication and division, an error bound for the relative error of the results is given by

h f h b d f h l i f

the sum of the bounds for the relative error of the given numbers

15

(16)

19 2 Solution of 19.2 Solution of

Equation by Iteration q o y o

(17)

19.2 Solution of Equation by Iteration

F(x) = 0

17

(18)

19.2 Solution of Equation by Iteration

F(x) = 0 F(x) 0

Zeros of Bessel function ?

(19)

19

(20)

19.2 Solution of Equation by Iteration

Algebraic equation Algebraic equation

Transcendental equation

(21)

19.2 Solution of Equation by Iteration

F(x) = 0

No formula for exact solution Approximation

Iteration method

21

(22)

19.2 Solution of Equation by Iteration

Iteration method Iteration method

Initial guess x 0 step by step x 1 x 2 step by step x 1 x 2 … Fi d i t it ti

Fixed point iteration Newton’s method

Secant method

(23)

19.2 Solution of Equation by Iteration

Fixed-point iteration p

Transform f(x) 0 to x g(x) Transform f(x)=0 to x=g(x)

Choose x 0 x 1 =g(x 0 ) x 2 2 =g(x g( 1 1 ) )

X n+1 n+1 =g(x g n n )

23

(24)

19.2 Solution of Equation by Iteration

Ex1. Fixed-point iteration p

Transform to x=g(x)

Converge

Diverge

(25)

19.2 Solution of Equation by Iteration

Ex1. Fixed-point iteration p

Divide by x

25

(26)

Indexing Indexing

Extract the index terms Extract the index terms Weights

Data structure

(27)

Header file Ex. stdlib.h

27

(28)

Data type Data type Int integer Int, integer

Long, long integer

Float, floating-point

Double, double precision floating point

(29)

Indexing Indexing

Extract the index terms Extract the index terms Weights

Data structure

29

(30)

Indexing Indexing

Extract the index terms Extract the index terms Weights

Data structure

(31)

x 0 =1 0 x 0 =1.0

31

(32)

3 0 x 0 =3.0

(+,-)1.#INF, infinite number NaN not a number =

NaN, not a number =

(+,-)1.#IND (indeterminate)

(33)

19.2 Solution of Equation by Iteration

Ex1. Fixed-point iteration p

lower part, the slope of g1(x) is less than the slope of y=x

of y x

upper part, the slope of g1(x) is steeper than the slope of y=x

|g1’(x)| < 1 is sufficient for convergence

1.0 3.0 33

(34)

C f Fi d P i t

19.1 Introduction

Convergence of Fixed-Point Iteration

Iteration

Th 1 C Th 1 C

Th.1 Convergence Th.1 Convergence

Let x=s be a solution of x=g(x) and suppose

that g has a continuous derivative in some

interval J containing s. Then if |g’(x)| ≤ K < 1 in

J, the iteration process defined by (3) converges

for any x

0

in J, and the limit of the sequence {x

n

}

is s.

(35)

C f Fi d P i t

19.2 Solution of Equation by Iteration

Convergence of Fixed-Point Iteration

Iteration

|g’(x)|<1

S S

J 35

(36)

Proof

19.2 Solution of Equation by Iteration

Proof

|g’(x)|<1

S S

(37)

19.2 Solution of Equation by Iteration

Ex1. Fixed-point iteration p

Transform to x=g(x)

| ’( )| |2 /3|

|g1’(x)| = |2x/3|<1

-3/2 < x < 3/2 의 어떤 x0에서라도 수렴

37

(38)

19.2 Solution of Equation by Iteration

Ex1. Fixed-point iteration p

Divide by x

|g1’(x)| = |1/x2|<1

1 1 의 어떤 에서라도 수렴

-∞< x <-1, 1<x<∞ 의 어떤 x0에서라도 수렴

(39)

19.2 Solution of Equation by Iteration

Iteration method Iteration method

Initial guess x 0 step by step x 1 x 2 step by step x 1 x 2 … Fi d i t it ti

Fixed point iteration Newton’s method

Secant method

39

(40)

19.2 Solution of Equation by Iteration

Newton’s Method

F(x)=0

Commonly used

Simplicity and great speed

Simplicity and great speed

(41)

19.2 Solution of Equation by Iteration

Newton’s Method

Idea Tangent

41

(42)

19.2 Solution of Equation by Iteration

Newton’s Method

(43)

Fail, Try another x0

Success

Fail, Try another x, y 00

43

(44)

19.2 Solution of Equation by Iteration

Ex3. Square Root q

(45)

45

(46)
(47)

19.2 Solution of Equation by Iteration

Ex4. Transcendental Equation q

47

(48)
(49)

49

(50)

19.2 Solution of Equation by Iteration

Ex5. Algebraic Equation g q

(51)

51

(52)
(53)

19.2 Solution of Equation by Iteration

Order of an Iteration method Speed of Convergence

53

(54)

19.2 Solution of Equation by Iteration

Subtract g(s)=s

xn+1 – s = -g’(s) єn + 1/2 g’’(s) єn2 + … є = g’(s) є + 1/2 g’’(s) є 2 +

n+1 = -g (s) єn + 1/2 g (s) єn2 + … єn+1 = g’(s) єn - 1/2 g’’(s) єn2 + …

(a) єn+1 ≈ g’(s) єn in the case of first order

(b) є +1 ≈ -1/2 g’’(s) є 2 in the case of second order (b) єn+1 ≈ 1/2 g (s) єn in the case of second order Ex. єn=10-k, єn+1 = c*(10-k)2=c*10-2k

(55)

C f N t ’

19.2 Solution of Equation by Iteration

Convergence of Newton’s Method

Method

єn+1

= g’(s)

єn

- 1/2 g’’(s)

єn2

+ …

єn+1

g (s)

єn

1/2 g (s)

єn

+ …

 єn+1 ≈ -1/2 g’’(s) єn2 , second order if f’ and f’’ are not zero at a solution s

55

(56)

Taylor Series

미분가능한 어떤 함수를 다항식의 형태 미분가능한 어떤 함수를 다항식의 형태 로 근사화하는 방법

어떤 한 점에서 그것의 미분값으로 계 산되는 항들의 무한 합으로 표현

(57)

Taylor Series Taylor Series

f(x) = c

0

+c

1

(x-a)+c

2

(x-a)

2

+c

3

(x-a)

3

+…

(

, |x-a|<R

때 수렴

)

( | | )

x=a, f(a) = c0

f’(x) = c1+2c2(x-a)+3c3(x-a)2+…

x=a, f’(a) = c1

f’’(x) = 2c2+3*2c3(x-a)+…

x=a, f’’(a) = 2c2, f’’(a)/2 = c2

Cn =

f’’’(x) = 3*2c3+…

x=a, f’’’(a) = c3, f’’’(a)/(3*2) = c3

57

(58)

Taylor Series Taylor Series

The Taylor series of a real or complex function ƒ(x) y p ƒ( ) that is infinitely differentiable in a neighborhood of a real or complex number a, is the power series

where n! denotes the factorial of n and ƒ (n)(a) denotes the nth

derivative of ƒ evaluated at the point a; the zeroth derivative of ƒ is derivative of ƒ evaluated at the point a; the zeroth derivative of ƒ is defined to be ƒ itself and (xa)0 and 0! are both defined to be 1.

In the particular case where a 0 the series is also

In the particular case where a = 0, the series is also

called a Maclaurin series.

(59)

처음 몇 항까지를 선택함으로써 x = a 주변에서의 f(x)의 근사식으로 사용

The exponential function y = ex (continuous red line) and the corresponding Taylor polynomial of degree four (dashed green line) around the origin

line) around the origin.

59

(60)

The exponential function (in blue) The exponential function (in blue), and the sum of the first n+1 terms of its Taylor series at 0 (in red).

(61)

19.2 Solution of Equation by Iteration

Iteration method Iteration method

Initial guess x 0 step by step x 1 x 2 step by step x 1 x 2 … Fi d i t it ti

Fixed point iteration Newton’s method

Secant method

61

(62)

19.2 Solution of Equation by Iteration

Secant Method

f’(x)

A far more difficult expression

Computationally expensive

Computationally expensive

(63)

19.2 Solution of Equation by Iteration

Secant Method

초기치 2개 필요 초기치 2개 필요

63

(64)

19.2 Solution of Equation by Iteration

Ex8. Secant Method

(65)

19.2 Solution of Equation by Iteration

Convergence of Secant Method Evaluation of derivatives

Avoided

Convergence

Almost quadratic like Newton Almost quadratic like Newton

|є | ≈ const| є |

1 62

n+1

| ≈ const| є

n

|

1.62

65

(66)

19.2 Solution of Equation by Iteration

Iteration method Iteration method

Initial guess x 0 step by step x 1 x 2 step by step x 1 x 2 … Fi d i t it ti

Fixed point iteration Newton’s method

Secant method

(67)

19.3 Interpolation

67

(68)

19.3 Interpolation

approximate values approximate values

of a function f(x) for an x

between different x-values x 0 ,x 1 ,…,x n

(69)

19.3 Interpolation

69

(70)

19.3 Interpolation

Lagrange Interpolation

(71)

19.3 Interpolation

y-f 1 =(f 1 -f 0 /x 1 -x 0 )(x-x 1 )

71

(72)

19.3 Interpolation

Lagrange Interpolation g g p Idea

Idea

(x 0 ,f 0 ), (x 1 ,f 1 )

x=x 0 P 1 (x)=f 0

x=x 0 , P 1 (x)=f 0

x=x 1 , P 1 (x)=f 1

(73)

19.3 Interpolation

(x 0 ,f 0 ), (x 1 , f 1 ) x=x 0 , P 1 (x)=f 0 x=x 1 P 1 (x)=f 1 x=x 1 , P 1 (x)=f 1

P (x ) =f L +f L =f (L =1 L =0) P 1 (x 0 ) =f 0 L 0 +f 1 L 1 =f 0 (L 0 =1, L 1 =0) P 1 (x 1 ) =f 0 L 0 +f 1 L 1 = f 1 (L 0 =0, L 1 =1) L 0 = (x-x 1 )/(x 0 -x 1 )

L 0 = (x x 1 )/(x 0 x 1 ) L 1 = (x-x 0 )/(x 1 -x 0 )

73

(74)

19.3 Interpolation

y-f

1

=(f

1

-f

0

/x

1

-x

0

)(x-x

1

) y=(f

1

-f

0

/x

1

-x

0

)(x-x

1

)+f

1

={(f

1

-f

0

)(x-x

1

)+f

1

(x

1

-x

0

)}/(x

1

-x

0

)

={(-f

0

)(x-x

1

)+f

1

(x-x

1

)+f

1

(x

1

-x

0

)}/(x

1

-x

0

)

={(-f

0

)(x-x

1

)+f

1

(x-x

0

)}/(x

1

-x

0

)

=(-f

0

)(x-x

1

) /(x

1

-x

0

)+f

1

(x-x

0

) /(x

1

-x

0

)

= f

0

(x-x

1

) /(x

0

-x

1

)+f

1

(x-x

0

) /(x

1

-x

0

)

= f

0

L

0

+f

1

L

1

(75)

19.3 Interpolation

Ex1. Linear Lagrange Interpolation

P

1

(x) =f

0

L

0

+f

1

L

1 ,

L = (x x )/(x x ) L = (x x )/(x x ) L

0

= (x-x

1

)/(x

0

-x

1

), L

1

= (x-x

0

)/(x

1

-x

0

)

75

(76)

19.3 Interpolation

L

0

= (x-x

1

)(x-x

2

)/(x

0

-x

1

)(x

0

-x

2

)

L

0

(x x

1

)(x x

2

)/(x

0

x

1

)(x

0

x

2

)

L

1

= (x-x

0

)(x-x

2

)/(x

1

-x

0

)(x

0

-x

2

)

L

2

= (x-x

0

)(x-x

1

)/(x

2

-x

0

)(x

2

-x

1

)

(77)

19.3 Interpolation

Quadratic Interpolation

Q p

three points three points

(x 0 ,f 0 ), (x 1 ,f 1 ), (x 2 ,f 2 ) x=x 0 , P 2 (x)=f 0

x=x 1 P 2 (x)=f 1 x=x 1 , P 2 (x)=f 1 x=x 2 , P 2 (x)=f 2

77

(78)

19.3 Interpolation

P 2 (x) =f 0 L 0 +f 1 L 1 +f 2 L 2 (x 0 ,f 0 ), (x 1 ,f 1 ), (x 2 ,f 2 )

x=x (L =1 L =0 L =0) x=x 0 , (L 0 =1, L 1 =0, L 2 =0) x=x 1 , (L 0 =0, L 1 =1, L 2 =0) x=x 2 , (L 0 =0, L 1 =0, L 2 =1)

L 0 = (x-x 1 )(x-x 2 )/(x 0 -x 1 )(x 0 -x 2 )

L ( )( )/( )( )

L 1 = (x-x 0 )(x-x 2 )/(x 1 -x 0 )(x 0 -x 2 )

L 2 2 = (x-x ( 0 0 )(x-x )( 1 1 )/(x )/( 2 2 -x 0 0 )(x )( 2 2 -x 1 1 ) )

(79)

19.3 Interpolation

Ex2. Quadratic Lagrange Interpolation

79

(80)

19.3 Interpolation

L ( )( )/( )( )

L

0

= (x-x

1

)(x-x

2

)/(x

0

-x

1

)(x

0

-x

2

)

L

1

= (x-x

0

)(x-x

2

)/(x

1

-x

0

)(x

0

-x

2

)

L

2

= (x-x

0

)(x-x

1

)/(x

2

-x

0

)(x

2

-x

1

)

(81)

19.3 Interpolation

L = (x x )(x x )/(x x )(x x ) L

0

= (x-x

1

)(x-x

2

)/(x

0

-x

1

)(x

0

-x

2

) L

1

= (x-x

0

)(x-x

2

)/(x

1

-x

0

)(x

0

-x

2

) Code

작성

Code

작성

81

(82)

19.3 Interpolation

General Lagrange

I t l ti P l i l

Interpolation Polynomial

(83)

Error Estimate

83

(84)

19.3 Interpolation

Ex3. Error Estimate of Linear Interpolation

9 0 ≤ t ≤ 9 5 9.0 ≤ t ≤ 9.5

(85)

19.3 Interpolation

Ex3. Error Estimate of Linear Interpolation

85

(86)

19.3 Interpolation

Ex3. Error Estimate of Linear Interpolation

(87)

Interpolation Interpolation

Linear Lagrange Interpolation

Quadratic Lagrange Interpolation Quadratic Lagrange Interpolation

General Lagrange Interpolation Error Estimate

87

(88)

19 5 Numeric Integration 19.5 Numeric Integration

& Differentiation

(89)

N i l ti f Numeric evaluation of

integrals integrals

89

(90)

Rectangular Rule

middle point of 1-st subinterval

(91)

Trapezoidal Rule

91

(92)

19.5 Numeric Integration

Ex1. Trapezoidal Rule

F(0)+f(1)

(93)

93

(94)

19.3 Interpolation

0.746824

(95)

19.3 Interpolation

95

(96)

19.3 Interpolation

0.746824

(97)

Error Bounds and

Estimate for Trapezoidal Rule

97

(98)

Error Bounds and

Estimate for Trapezoidal Rule

(99)

Error Bounds and

Estimate for Trapezoidal Rule

99

(100)

Error Bounds and

Estimate for Trapezoidal Rule

f

(101)

19.5 Numeric Integration

Ex2. Error Estimation for Trapezoidal Rule

101

(102)

Simpson’s Rule Simpson s Rule

of Integration

(103)

Piecewise constant approximation pp Rectangular rule

Piecewise linear approximation Trapezoidal rule

Trapezoidal rule

Piecewise quadratic approximation Simpson’s rule p

103

(104)

Divide the interval

i t b

into even number

of equal subintervals

of equal subintervals

(105)

19.5 Numeric Integration

105

(106)

-h -2h h -h 2h h

(107)

19.5 Numeric Integration

107

(108)
(109)

Error of Simpson’s Rule Error Bound

19.5 Numeric Integration

Error of Simpson s Rule, Error Bound, Degree of Precision

Because Simpson rule uses second order, if n=2, error of Simpson rule has f(3) derivatives ((5) in pp.800 & (3*) in pp.819).

B hi th bl i T l l i l

By approaching the problem using Taylor polynomial, we can derive the error involves the fourth derivative of f(4) .

Simpson’s rule gives exact results when applied to any polynomial of degree three or less

polynomial of degree three or less.

109

(110)

Error of Simpson’s Rule Error Bound

19.5 Numeric Integration

Error of Simpson s Rule, Error Bound,

Degree of Precision

(111)

Error of Simpson’s Rule Error Bound

19.5 Numeric Integration

Error of Simpson s Rule, Error Bound, Degree of Precision

111

(112)

Error of Simpson’s Rule Error Bound

19.5 Numeric Integration

Error of Simpson s Rule, Error Bound, Degree of Precision

Newton–Cotes formulas are a group of formulas for numerical integration based on

evaluating the integrand at equally-spaced points

Closed Newton-cotes formula, [a,b]

Open Newton-cotes formula, (a,b)

(113)

Numeric Differentiation

113

(114)

Computation of values of derivative of f(x)

from a given value of f(x)

from a given value of f(x)

(115)

Numeric differentiation should be avoided

whenever possible whenever possible

115

(116)

큰 값의 작은 차를 큰 값의 작은 차를

작은 양으로 나눈 것의 극한

약간의 부정확한

f(x)

값이라도 약간의 부정확한

f(x)

값이라도

f’(x)

에 큰 영향을 줄 수 있음

(117)

19.5 Numeric Differentiation

f(x ) f(x1) f(x0)

x0 x1/2x1 h

117

(118)

19.5 Numeric Differentiation

f(x) = x

4

f’(1.5) = ?

f(x ) f(x1) f(x0)

1.5 x1/2 2.0

x1 1.0

x0

118 x1/2

h=1

x1 x0

(119)

f’’(x ) ?

19.5 Numeric Differentiation

f’’(x

1

) = ?

119

(120)

19.3 Interpolation

f(x) x

4

f(x) = x

4

f’’(2) = ?

(121)

Lagrange polynomial Lagrange polynomial

approximation, differentiation

P

2

(x) =f

0

L

0

+f

1

L

1

+f

2

L

2

-h -2h

L

0

= (x-x

1

)(x-x

2

)/(x

0

-x

1

)(x

0

-x

2

) L

1

= (x-x

0

)(x-x

2

)/(x

1

-x

0

)(x

0

-x

2

)

L ( )( )/( )( )

L

2

= (x-x

0

)(x-x

1

)/(x

2

-x

0

)(x

2

-x

1

)

121

(122)

Lagrange polynomial Lagrange polynomial

approximation, differentiation

x=x0 x=x1 x=x2

(123)

Numeric Integration g

Rectangular Rule Trapezoidal Rule Trapezoidal Rule

Simpson Rule Error Estimate

Differentiation Differentiation

123

Referensi

Dokumen terkait

The following table illustrated the errors made by the students found in students’ writing result: Table 5 Total Of Error About Word Order Error In Recoun Text No Classification

Keywords: AIDS, wet granulation, in vitro drug release, stability study INRODUCTION Controlled release dosage forms offer prolong drug release of active ingredients at a