16
1 Approximation Approximation

1 Approximation. 2 Taylor Series 3 Truncation Error In general, the nth order Taylor series expansion will be exact for an nth order polynomial In

Embed Size (px)

Citation preview

Page 1: 1 Approximation. 2 Taylor Series 3 Truncation Error  In general, the nth order Taylor series expansion will be exact for an nth order polynomial  In

1

ApproximationApproximation

Page 2: 1 Approximation. 2 Taylor Series 3 Truncation Error  In general, the nth order Taylor series expansion will be exact for an nth order polynomial  In

2

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

Taylor Series

Page 3: 1 Approximation. 2 Taylor Series 3 Truncation Error  In general, the nth order Taylor series expansion will be exact for an nth order polynomial  In

3

Truncation 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 4: 1 Approximation. 2 Taylor Series 3 Truncation Error  In general, the nth order Taylor series expansion will be exact for an nth order polynomial  In

Numerical Differentiation

Problem: approximate the derivative of the function f(x) knowing the values of the function at discrete values of x

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

4

f (x i1) f (x i) f'(x i)h O(h2)

f '(x i)f (x i1) f (x i)

hO(h)

Page 5: 1 Approximation. 2 Taylor Series 3 Truncation Error  In general, the nth order Taylor series expansion will be exact for an nth order polynomial  In

Numerical Differentiation ( 續 )

There are also backward difference and centered difference approx., depending on the points used: Forward

Backward

Centered

5

f '(x i)f (x i1) f (x i)

hO(h)

f '(x i)f (x i) f (x i 1)

hO(h)

f '(x i)f (x i1) f (x i 1)

2hO(h2)

Page 6: 1 Approximation. 2 Taylor Series 3 Truncation Error  In general, the nth order Taylor series expansion will be exact for an nth order polynomial  In

Truncation and Round-off Errors

Truncation error (截斷誤差 ): method dependent Results from ignoring all but a finite number of terms of an

infinite series  Results from using an approximation rather than an exact

procedure

Round-off error (捨入誤差 ): machine dependent Difference between an approximation of a number used in

computation and its exact (correct) value Results from not being able to adequately represent the

true value

6

....)x(f!3

h)x(f

!2

h)x(fh)x(f)hx(f i

3

i

2

iii

71828.2e ,1416.3

Page 7: 1 Approximation. 2 Taylor Series 3 Truncation Error  In general, the nth order Taylor series expansion will be exact for an nth order polynomial  In

Truncation and Round-off Errors

Round-off error (捨入誤差 ): machine dependent An example of round-off error is provided by an index

devised at the Vancouver stock exchange. At its inception in 1982, the index was given a value of 1000.000. After 22 months of recomputing the index and truncating to three decimal places at each change in market value, the index stood at 524.881, despite the fact that its "true" value should have been 1009.811

Another example is the fate of the Ariane rocket launched on June 4, 1996 (European Space Agency 1996). In the 37th second of flight, the inertial reference system attempted to convert a 64-bit floating-point number to a 16-bit number, but instead triggered an overflow error which was interpreted by the guidance system as flight data, causing the rocket to veer off course and be destroyed.

7

Page 8: 1 Approximation. 2 Taylor Series 3 Truncation Error  In general, the nth order Taylor series expansion will be exact for an nth order polynomial  In

function sum = exp(x)% Evaluate exponential function exp(x) % by Taylor series expansion% f(x)=1 + x + x^2/2! + x^3/3! + … + x^n/n!

clear allx = input(‘enter the value of x = ’);n = input(‘enter the order n = ’);term =1 ; sum= term;for i = 1 : n term = term*x/i; sum = sum + term;end

Truncation Error Example

Page 9: 1 Approximation. 2 Taylor Series 3 Truncation Error  In general, the nth order Taylor series expansion will be exact for an nth order polynomial  In

function sum = exp(x)% Evaluate exponential function exp(x) % by Taylor series expansion% f(x)=1 + x + x^2/2! + x^3/3! + … + x^n/n!x = input(‘enter the value of x =’);n = input(‘enter the order n = ’);term(1) =1 ; sum(1)= term(1);for i = 1 : n term(i+1) = term(i)*x/i; sum(i+1) = sum(i) + term(i+1);end% Display the resultsdisp(‘i term(i) sum(i)’)a = 1:n+1; [a’ term’ sum’]

Truncation Error Example

Page 10: 1 Approximation. 2 Taylor Series 3 Truncation Error  In general, the nth order Taylor series expansion will be exact for an nth order polynomial  In

0 1.0000 1.0000 1 10.0000 11.0000 2 50.0000 61.0000 3 166.6667 227.6667 4 416.6667 644.3334 5 833.3334 1477.6667 6 1388.8890 2866.5557 7 1984.1272 4850.6826 8 2480.1589 7330.8418 9 2755.7322 10086.5742 10 2755.7322 12842.3066 11 2505.2112 15347.5176 12 2087.6760 17435.1934 13 1605.9045 19041.0977 14 1147.0746 20188.1719 15 764.7164 20952.8887 16 477.9478 21430.8359 17 281.1458 21711.9824 18 156.1921 21868.1738 19 82.2064 21950.3809 20 41.1032 21991.4844

21 19.5729 22011.0566 22 8.8968 22019.9531 23 3.8682 22023.8223 24 1.6117 22025.4336 25 0.6447 22026.0781 26 0.2480 22026.3262 27 0.0918 22026.4180 28 0.0328 22026.4512 29 0.0113 22026.4629 30 0.0038 22026.4668 31 0.0012 22026.4688 32 0.0004 22026.4688 33 0.0001 22026.4688 34 0.0000 22026.4688 35 0.0000 22026.4688 36 0.0000 22026.4688 37 0.0000 22026.4688 38 0.0000 22026.4688 39 0.0000 22026.4688 40 0.0000 22026.4688

n term sum n term sum

4658.22026e ,10 x xTruncation Error

Page 11: 1 Approximation. 2 Taylor Series 3 Truncation Error  In general, the nth order Taylor series expansion will be exact for an nth order polynomial  In

n term sum n term sum

Truncation Error 4x 1045399.0e ,10 x

0 1.0000000 1.0000000 1 -10.0000000 -9.0000000 2 50.0000000 41.0000000 3 -166.6666718 -125.6666718 4 416.6666870 291.0000000 5 -833.3333740 -542.3333740 6 1388.8890381 846.5556641 7 -1984.1271973 -1137.5715332 8 2480.1589355 1342.5874023 9 -2755.7321777 -1413.1447754 10 2755.7321777 1342.5874023 11 -2505.2111816 -1162.6237793 12 2087.6760254 925.0522461 13 -1605.9045410 -680.8522949 14 1147.0745850 466.2222900 15 -764.7164307 -298.4941406 16 477.9477539 179.4536133 17 -281.1457520 -101.6921387 18 156.1920776 54.4999390 19 -82.2063599 -27.7064209 20 41.1031799 13.3967590

21 -19.5729427 -6.1761837 22 8.8967924 2.7206087 23 -3.8681707 -1.1475620 24 1.6117378 0.4641758 25 -0.6446951 -0.1805193 26 0.2479596 0.0674404 27 -0.0918369 -0.0243965 28 0.0327989 0.0084024 29 -0.0113100 -0.0029076 30 0.0037700 0.0008624 31 -0.0012161 -0.0003537 32 0.0003800 0.0000263 33 -0.0001152 -0.0000889 34 0.0000339 -0.0000550 35 -0.0000097 -0.0000647 36 0.0000027 -0.0000620 37 -0.0000007 -0.0000627 38 0.0000002 -0.0000625 39 0.0000000 -0.0000626 40 0.0000000 -0.0000626

4658.22026/110 eHow to reduce error?

Page 12: 1 Approximation. 2 Taylor Series 3 Truncation Error  In general, the nth order Taylor series expansion will be exact for an nth order polynomial  In
Page 13: 1 Approximation. 2 Taylor Series 3 Truncation Error  In general, the nth order Taylor series expansion will be exact for an nth order polynomial  In

Accuracy and Precision

Accuracy - How closely a measured or computed value agrees with the true value

Precision - How closely individual measured or computed values agree with each other

Accuracy is getting all your shots near the target Precision is getting them close together.

13

More Accurate

More Precise

Page 14: 1 Approximation. 2 Taylor Series 3 Truncation Error  In general, the nth order Taylor series expansion will be exact for an nth order polynomial  In

Effect of the Step Size on the Total Error

Truncation and round-off errors behave differently as functions of the step size h: Truncation error increases as the step size increases Round-off error decreases as the step size increases

Total numerical error = truncation + round-off error There is an optimum step size which minimizes the

total error

14

Page 15: 1 Approximation. 2 Taylor Series 3 Truncation Error  In general, the nth order Taylor series expansion will be exact for an nth order polynomial  In

Effect of the Step Size

The smaller the step size The larger the number of calculations, thus the larger the

round-off error The smaller the error made when approximation the value

of the function at the intermediate points

15

Page 16: 1 Approximation. 2 Taylor Series 3 Truncation Error  In general, the nth order Taylor series expansion will be exact for an nth order polynomial  In

16

Other 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