Upload
others
View
0
Download
0
Embed Size (px)
Citation preview
Chapter 19Chapter 19Chapter 19Chapter 19NumericsNumerics in Generalin General
Bo-Yeong Kang, 2009Kyungpook National University
1
What is What is numerical analysis ?y
2
The study of algorithms to sol e the problems thatsolve the problems thatthere is no solution formula
3
19.1 Introduction
The steps from problems p pto answer
ModelingModelingChoosing a numeric methodsprogrammingprogrammingDoing the computationInterpreting the results
4
19.1 Introduction
Real number
Fl ti i t f f Floating point form of numbersnumbers
0.6247*103, 0.735*10-13, -0.2000*10-1
Number of significant digits is kept fixedg g pDecimal point “floating”
5
19.1 Introduction
Floating point form of Floating point form of numbersnumbers
a = m*10n , 0.1≤|m| < 1On computers, m & n is limitedp ,ā = m*10n , m=0.d1d2…dk, d1>0
mantissa
exponent
mantissa
6
19.1 Introduction
Floating point form of n mbe snumbers
ā = m*10n , m=0.d1d2…dk, d1>0mantissa
exponent
exponent
tisign mantissaIBM 3000 & 4000 series
Single precision floating point number1 sign, 7 exponent, 24 mantissa, 32 bits
7
19.1 Introduction
Floating point form of oat g po t o onumbers
The number outside that range occursUnderflow when the number is smaller (zero)Overflow when it is larger (halt)
exponent
sign mantissa
8
19.1 Introduction
Roundoff(끝처리)mantissa
Roundoff(끝처리)
0.d1d2…dkdk+1dk +2dk+3 …Roundoff ruleDiscard (k+1)th and all subsequent decimalsDiscard (k+1)th and all subsequent decimalsIf 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
19.1 Introduction
Error in RoundingError 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| ≤ ½ * 101-k
Error bound in rounding
10
19.1 Introduction
Errors of Numeric Results
Finding the results – ApproximationRounding errorsExperimental errors from measurementsT ncating e o s f om p emat el b eaking offTruncating errors from prematurely breaking off
Formulas for ErrorsFormulas for Errorsє = a – ãa = ã + є , True value = Approximation + errora ã + є , True value Approximation + errorã = 10.5, a=10.2, є = -0.3
11
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
12
19.1 Introduction
E P tiError Propagation
How errors at the beginning and in later steps propagate into the computation and affect accuracy
(a) Subtractionx = 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
19.1 Introduction
Error PropagationError Propagation
(b) Relative error of multiplicationx = x+ є1 , y=ỹ+ є2 , |єr1|≤ r1 , |єr2| ≤ r2
|( ỹ)/ |єr = |(xy – xỹ)/xy|= |(xy – (x- є1)(y-є2))/xy|
|( )/ |= |(є1y+є2y-є1є2)/xy| ≈ |(є1y+є2x)/xy|
| / | | / | | | | | ≤ | є1/x |+ |є2 /y| = |єr1|+|єr2| ≤ r1 + r2
14
19.1 Introduction
Error PropagationError PropagationTh 1 E P iTh 1 E P iTh.1 Error PropagationTh.1 Error Propagation
(a)In addition and subtraction, an error boundf th lt i i b th f thfor the results is given by the sum of the errorbounds for the terms(b)I lti li ti d di i i b d(b)In multiplication and division, an error boundfor the relative error of the results is given byh f h b d f h l i fthe sum of the bounds for the relative error of
the given numbers
15
19 2 Solution of 19.2 Solution of Equation by Iterationq o y o
16
19.2 Solution of Equation by Iteration
F(x) = 0
17
19.2 Solution of Equation by Iteration
F(x) = 0F(x) 0Zeros of Bessel function ?
18
19
19.2 Solution of Equation by Iteration
Algebraic equationAlgebraic equationTranscendental equation
20
19.2 Solution of Equation by Iteration
F(x) = 0
No formula for exact solutionApproximation
Iteration method
21
19.2 Solution of Equation by Iteration
Iteration methodIteration method
Initial guess x0step by step x1 x2 step by step x1 x2 …
Fi d i t it tiFixed point iterationNewton’s method
Secant method
22
19.2 Solution of Equation by Iteration
Fixed-point iterationp
Transform f(x) 0 to x g(x)Transform f(x)=0 to x=g(x)Choose x0x1 =g(x0)x2 =g(x1)2 g( 1)…Xn+1 =g(xn)n+1 g n
23
19.2 Solution of Equation by Iteration
Ex1. Fixed-point iterationp
Transform to x=g(x)
Converge
Diverge24
19.2 Solution of Equation by Iteration
Ex1. Fixed-point iterationp
Divide by x
25
Indexing Indexing
Extract the index terms Extract the index terms Weights Data structure
26
Header fileEx. stdlib.h
27
Data typeData type
Int integerInt, integer
Long, long integer
Float, floating-point
Double, double precision floating point
28
Indexing Indexing
Extract the index terms Extract the index terms Weights Data structure
29
Indexing Indexing
Extract the index terms Extract the index terms Weights Data structure
30
x0 =1 0x0 =1.0
31
3 0x0 =3.0
(+,-)1.#INF, infinite numberNaN not a number =NaN, not a number =(+,-)1.#IND (indeterminate)
32
19.2 Solution of Equation by Iteration
Ex1. Fixed-point iterationp
lower part, the slope of g1(x) is less than the slope of y=xof 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
C f Fi d P i t 19.1 Introduction
Convergence of Fixed-Point IterationIteration
Th 1 CTh 1 CTh.1 ConvergenceTh.1 Convergence
Let x=s be a solution of x=g(x) and supposethat g has a continuous derivative in someinterval J containing s. Then if |g’(x)| ≤ K < 1 inJ, the iteration process defined by (3) convergesfor any x0 in J, and the limit of the sequence {xn}is s.
34
C f Fi d P i t 19.2 Solution of Equation by Iteration
Convergence of Fixed-Point IterationIteration
|g’(x)|<1
SS
J35
Proof19.2 Solution of Equation by Iteration
Proof
|g’(x)|<1
SS
36
19.2 Solution of Equation by Iteration
Ex1. Fixed-point iterationp
Transform to x=g(x)
| ’( )| |2 /3||g1’(x)| = |2x/3|<1-3/2 < x < 3/2 의 어떤 x0에서라도 수렴
37
19.2 Solution of Equation by Iteration
Ex1. Fixed-point iterationp
Divide by x
|g1’(x)| = |1/x2|<1 1 1 의 어떤 에서라도 수렴-∞< x <-1, 1<x<∞ 의 어떤 x0에서라도 수렴
38
19.2 Solution of Equation by Iteration
Iteration methodIteration method
Initial guess x0step by step x1 x2 step by step x1 x2 …
Fi d i t it tiFixed point iterationNewton’s method
Secant method
39
19.2 Solution of Equation by Iteration
Newton’s Method
F(x)=0
Commonly usedSimplicity and great speedSimplicity and great speed
40
19.2 Solution of Equation by Iteration
Newton’s Method
Idea
Tangent
41
19.2 Solution of Equation by Iteration
Newton’s Method
42
Fail, Try another x0
Success
Fail, Try another x0, y 0
43
19.2 Solution of Equation by Iteration
Ex3. Square Rootq
44
45
46
19.2 Solution of Equation by Iteration
Ex4. Transcendental Equationq
47
48
49
19.2 Solution of Equation by Iteration
Ex5. Algebraic Equationg q
50
51
52
19.2 Solution of Equation by Iteration
Order of an Iteration methodSpeed of Convergence
53
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
54
C f N t ’ 19.2 Solution of Equation by Iteration
Convergence of Newton’s MethodMethod
є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
Taylor Series
미분가능한 어떤 함수를 다항식의 형태미분가능한 어떤 함수를 다항식의 형태로 근사화하는 방법
어떤 한 점에서 그것의 미분값으로 계산되는 항들의 무한 합으로 표현
56
Taylor SeriesTaylor Series
f(x) = c0+c1(x-a)+c2(x-a)2+c3(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
Taylor SeriesTaylor SeriesThe 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 (x − a)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.
58
처음 몇 항까지를 선택함으로써 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 originline) around the origin.
59
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).
60
19.2 Solution of Equation by Iteration
Iteration methodIteration method
Initial guess x0step by step x1 x2 step by step x1 x2 …
Fi d i t it tiFixed point iterationNewton’s method
Secant method
61
19.2 Solution of Equation by Iteration
Secant Method
f’(x)
A far more difficult expressionComputationally expensiveComputationally expensive
62
19.2 Solution of Equation by Iteration
Secant Method
초기치 2개 필요초기치 2개 필요
63
19.2 Solution of Equation by Iteration
Ex8. Secant Method
64
19.2 Solution of Equation by Iteration
Convergence of Secant Method
Evaluation of derivativesAvoided
Convergence Almost quadratic like NewtonAlmost quadratic like Newton
|є | ≈ const| є |1 62|єn+1| ≈ const| єn |1.62
65
19.2 Solution of Equation by Iteration
Iteration methodIteration method
Initial guess x0step by step x1 x2 step by step x1 x2 …
Fi d i t it tiFixed point iterationNewton’s method
Secant method
66
19.3 Interpolation
67
19.3 Interpolation
approximate values approximate values of a function f(x) for an x
between different x-values x0,x1,…,xn
68
19.3 Interpolation
69
19.3 Interpolation
Lagrange Interpolation
70
19.3 Interpolation
y-f1=(f1-f0/x1-x0)(x-x1)
71
19.3 Interpolation
Lagrange Interpolationg g p
IdeaIdea
(x0,f0), (x1,f1)x=x0 P1(x)=f0x=x0, P1(x)=f0x=x1, P1(x)=f1
72
19.3 Interpolation
(x0,f0), (x1, f1)x=x0, P1(x)=f0x=x1 P1(x)=f1x=x1, P1(x)=f1
P (x ) =f L +f L =f (L =1 L =0)P1(x0) =f0L0+f1L1 =f0 (L0=1, L1=0)P1(x1) =f0L0+f1L1 = f1 (L0=0, L1=1)
L0= (x-x1)/(x0-x1)L0= (x x1)/(x0 x1)L1= (x-x0)/(x1-x0)
73
19.3 Interpolation
y-f1=(f1-f0/x1-x0)(x-x1)y=(f1-f0/x1-x0)(x-x1)+f1={(f1-f0)(x-x1)+f1(x1-x0)}/(x1-x0)={(-f0)(x-x1)+f1(x-x1)+f1(x1-x0)}/(x1-x0)={(-f0)(x-x1)+f1(x-x0)}/(x1-x0) =(-f0)(x-x1) /(x1-x0)+f1(x-x0) /(x1-x0)= f0(x-x1) /(x0-x1)+f1(x-x0) /(x1-x0)= f0L0+f1L1 74
19.3 Interpolation
Ex1. Linear Lagrange Interpolation
P1(x) =f0L0+f1L1 ,L = (x x )/(x x ) L = (x x )/(x x ) L0= (x-x1)/(x0-x1), L1= (x-x0)/(x1-x0)
75
19.3 Interpolation
L0= (x-x1)(x-x2)/(x0-x1)(x0-x2)L0 (x x1)(x x2)/(x0 x1)(x0 x2)L1= (x-x0)(x-x2)/(x1-x0)(x0-x2)L2= (x-x0)(x-x1)/(x2-x0)(x2-x1)
76
19.3 Interpolation
Quadratic InterpolationQ p
three pointsthree points(x0,f0), (x1,f1), (x2,f2)
x=x0, P2(x)=f0x=x1 P2(x)=f1 x=x1, P2(x)=f1 x=x2, P2(x)=f2
77
19.3 Interpolation
P2(x) =f0L0+f1L1+f2L2
(x0,f0), (x1,f1), (x2,f2)x=x (L =1 L =0 L =0) x=x0, (L0=1, L1=0, L2=0) x=x1, (L0=0, L1=1, L2=0) x=x2, (L0=0, L1=0, L2=1)
L0= (x-x1)(x-x2)/(x0-x1)(x0-x2)L ( )( )/( )( )L1= (x-x0)(x-x2)/(x1-x0)(x0-x2)L2= (x-x0)(x-x1)/(x2-x0)(x2-x1)2 ( 0)( 1)/( 2 0)( 2 1)
78
19.3 Interpolation
Ex2. Quadratic Lagrange Interpolation
79
19.3 Interpolation
L ( )( )/( )( )L0= (x-x1)(x-x2)/(x0-x1)(x0-x2)L1= (x-x0)(x-x2)/(x1-x0)(x0-x2)L2= (x-x0)(x-x1)/(x2-x0)(x2-x1)
80
19.3 Interpolation
L = (x x )(x x )/(x x )(x x )L0= (x-x1)(x-x2)/(x0-x1)(x0-x2)L1= (x-x0)(x-x2)/(x1-x0)(x0-x2)Code 작성Code 작성
81
19.3 Interpolation
General Lagrange I t l ti P l i lInterpolation Polynomial
82
Error Estimate
83
19.3 Interpolation
Ex3. Error Estimate of Linear Interpolation
9 0 ≤ t ≤ 9 59.0 ≤ t ≤ 9.5
84
19.3 Interpolation
Ex3. Error Estimate of Linear Interpolation
85
19.3 Interpolation
Ex3. Error Estimate of Linear Interpolation
86
InterpolationInterpolation
Linear Lagrange InterpolationQuadratic Lagrange Interpolation Quadratic Lagrange Interpolation General Lagrange Interpolation
Error Estimate
87
19 5 Numeric Integration 19.5 Numeric Integration & Differentiation
88
N i l ti f Numeric evaluation of integralsintegrals
89
Rectangular Rule
middle point of 1-st subinterval
90
Trapezoidal Rule
91
19.5 Numeric Integration
Ex1. Trapezoidal Rule
F(0)+f(1)
92
93
19.3 Interpolation
0.746824
94
19.3 Interpolation
95
19.3 Interpolation
0.746824
96
Error Bounds and Estimate for Trapezoidal Rule
97
Error Bounds and Estimate for Trapezoidal Rule
98
Error Bounds and Estimate for Trapezoidal Rule
99
Error Bounds and Estimate for Trapezoidal Rule
f
100
19.5 Numeric Integration
Ex2. Error Estimation for Trapezoidal Rule
101
Simpson’s Rule Simpson s Rule of Integration
102
Piecewise constant approximation ppRectangular rule
Piecewise linear approximationTrapezoidal ruleTrapezoidal rule
Piecewise quadratic approximationSimpson’s rulep
103
Divide the intervali t binto even number
of equal subintervalsof equal subintervals
104
19.5 Numeric Integration
105
-h -2h h -h 2h h
106
19.5 Numeric Integration
107
108
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 ofSimpson rule has f(3) derivatives ((5) in pp.800 & (3*) in pp.819).B hi th bl i T l l i lBy approaching the problem using Taylor polynomial, we canderive the error involves the fourth derivative of f(4) .Simpson’s rule gives exact results when applied to anypolynomial of degree three or lesspolynomial of degree three or less.
109
Error of Simpson’s Rule Error Bound
19.5 Numeric Integration
Error of Simpson s Rule, Error Bound, Degree of Precision
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
• 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)
112
Numeric Differentiation
113
Computation of values of derivative of f(x)
from a given value of f(x)from a given value of f(x)
114
Numeric differentiation should be avoided whenever possiblewhenever possible
115
큰 값의 작은 차를큰 값의 작은 차를작은 양으로 나눈 것의 극한
약간의 부정확한 f(x) 값이라도약간의 부정확한 f(x) 값이라도f’(x)에 큰 영향을 줄 수 있음
116
19.5 Numeric Differentiation
f(x )f(x1)f(x0)
x0 x1x1/2
h
117
19.5 Numeric Differentiation
f(x) = x4
f’(1.5) = ?
f(x )f(x1)f(x0)
1.5x1/2
2.0x1
1.0x0
118
x1/2
h=1
x1 x0
f’’(x ) ?
19.5 Numeric Differentiation
f’’(x1) = ?
119
19.3 Interpolation
f(x) x4f(x) = x4
f’’(2) = ?
120
Lagrange polynomial Lagrange polynomial approximation, differentiation
P2(x) =f0L0+f1L1+f2L2-h -2h
L0= (x-x1)(x-x2)/(x0-x1)(x0-x2)L1= (x-x0)(x-x2)/(x1-x0)(x0-x2)L ( )( )/( )( )L2= (x-x0)(x-x1)/(x2-x0)(x2-x1)
121
Lagrange polynomial Lagrange polynomial approximation, differentiation
x=x0
x=x1
x=x2122
Numeric Integration gRectangular RuleTrapezoidal RuleTrapezoidal Rule
Simpson RuleError Estimate
DifferentiationDifferentiation
123