• 沒有找到結果。

師大

師大

Solution

Using the quadratic formula and 8-digit rounding arithmetic, one can obtain

x1 = −0.01610723 and x2 = −62.08390.

Now we perform the calculations with 4-digit rounding arithmetic. First we have

pb2− 4ac =p

62.102− 4.000 =√

3856 − 4.000 = 62.06, and

f l(x1) = −62.10 + 62.06

2.000 = −0.04000

2.000 = −0.02000.

The relative error in computing x1is

|f l(x1) − x1|

|x1| = | − 0.02000 + 0.01610723|

| − 0.01610723| ≈ 0.2417 ≤ 5×10−1.

82 / 116

師大

Solution

Using the quadratic formula and 8-digit rounding arithmetic, one can obtain

x1 = −0.01610723 and x2 = −62.08390.

Now we perform the calculations with 4-digit rounding arithmetic. First we have

pb2− 4ac =p

62.102− 4.000 =√

3856 − 4.000 = 62.06, and

f l(x1) = −62.10 + 62.06

2.000 = −0.04000

2.000 = −0.02000.

The relative error in computing x1is

|f l(x1) − x1|

|x1| = | − 0.02000 + 0.01610723|

| − 0.01610723| ≈ 0.2417 ≤ 5×10−1.

83 / 116

師大

In calculating x2,

f l(x2) = −62.10 − 62.06

2.000 = −124.2

2.000 = −62.10, and the relative error in computing x2 is

|f l(x2) − x2|

|x2| = | − 62.10 + 62.08390|

| − 62.08390| ≈ 0.259×10−3 ≤ 5×10−4. In this equation, b2 = 62.102is much larger than 4ac = 4.

Hence b and√

b2− 4ac become two nearly equal numbers.

The calculation of x1 involves the subtraction of two nearly equal numbers.

To obtain a more accurate 4-digit rounding approximation for x1, we change the formulation by rationalizing the numerator, that is,

x1 = −2c

b +√

b2− 4ac.

84 / 116

師大

In calculating x2,

f l(x2) = −62.10 − 62.06

2.000 = −124.2

2.000 = −62.10, and the relative error in computing x2 is

|f l(x2) − x2|

|x2| = | − 62.10 + 62.08390|

| − 62.08390| ≈ 0.259×10−3 ≤ 5×10−4. In this equation, b2 = 62.102is much larger than 4ac = 4.

Hence b and√

b2− 4ac become two nearly equal numbers.

The calculation of x1 involves the subtraction of two nearly equal numbers.

To obtain a more accurate 4-digit rounding approximation for x1, we change the formulation by rationalizing the numerator, that is,

x1 = −2c b +√

b2− 4ac.

85 / 116

師大

In calculating x2,

f l(x2) = −62.10 − 62.06

2.000 = −124.2

2.000 = −62.10, and the relative error in computing x2 is

|f l(x2) − x2|

|x2| = | − 62.10 + 62.08390|

| − 62.08390| ≈ 0.259×10−3 ≤ 5×10−4. In this equation, b2 = 62.102is much larger than 4ac = 4.

Hence b and√

b2− 4ac become two nearly equal numbers.

The calculation of x1 involves the subtraction of two nearly equal numbers.

To obtain a more accurate 4-digit rounding approximation for x1, we change the formulation by rationalizing the numerator, that is,

x1 = −2c b +√

b2− 4ac.

86 / 116

師大

In calculating x2,

f l(x2) = −62.10 − 62.06

2.000 = −124.2

2.000 = −62.10, and the relative error in computing x2 is

|f l(x2) − x2|

|x2| = | − 62.10 + 62.08390|

| − 62.08390| ≈ 0.259×10−3 ≤ 5×10−4. In this equation, b2 = 62.102is much larger than 4ac = 4.

Hence b and√

b2− 4ac become two nearly equal numbers.

The calculation of x1 involves the subtraction of two nearly equal numbers.

To obtain a more accurate 4-digit rounding approximation for x1, we change the formulation by rationalizing the numerator, that is,

x1 = −2c

b +√

b2− 4ac.

87 / 116

師大

Then

f l(x1) = −2.000

62.10 + 62.06 = −2.000

124.2 = −0.01610.

The relative error in computing x1 is now reduced to 6.2 × 10−4

Example 13 Let

p(x) = x3− 3x2+ 3x − 1, q(x) = ((x − 3)x + 3)x − 1.

Compare the function values at x = 2.19 with using three-digit arithmetic.

88 / 116

師大

Then

f l(x1) = −2.000

62.10 + 62.06 = −2.000

124.2 = −0.01610.

The relative error in computing x1 is now reduced to 6.2 × 10−4

Example 13 Let

p(x) = x3− 3x2+ 3x − 1, q(x) = ((x − 3)x + 3)x − 1.

Compare the function values at x = 2.19 with using three-digit arithmetic.

89 / 116

師大

Solution

Use 3-digit and rounding for p(2.19) and q(2.19).

ˆ

p(2.19) = ((2.193− 3 × 2.192) + 3 × 2.19) − 1

= ((10.5 − 14.4) + 3 × 2.19) − 1

= (−3.9 + 6.57) − 1

= 2.67 − 1 = 1.67 and

ˆ

q(2.19) = ((2.19 − 3) × 2.19 + 3) × 2.19 − 1

= (−0.81 × 2.19 + 3) × 2.19 − 1

= (−1.77 + 3) × 2.19 − 1

= 1.23 × 2.19 − 1

= 2.69 − 1 = 1.69.

90 / 116

師大

With more digits, one can have

p(2.19) = g(2.19) = 1.685159 Hence the absolute errors are

|p(2.19) − ˆp(2.19)| = 0.015159 and

|q(2.19) − ˆq(2.19)| = 0.004841,

respectively. One can observe that the evaluation formula q(x) is better than p(x).

91 / 116

師大

With more digits, one can have

p(2.19) = g(2.19) = 1.685159 Hence the absolute errors are

|p(2.19) − ˆp(2.19)| = 0.015159 and

|q(2.19) − ˆq(2.19)| = 0.004841,

respectively.One can observe that the evaluation formula q(x) is better than p(x).

92 / 116

師大

With more digits, one can have

p(2.19) = g(2.19) = 1.685159 Hence the absolute errors are

|p(2.19) − ˆp(2.19)| = 0.015159 and

|q(2.19) − ˆq(2.19)| = 0.004841,

respectively. One can observe that the evaluation formula q(x) is better than p(x).

93 / 116

師大

Exercise

Page 28: 4, 11, 12, 15, 18

94 / 116

師大

Definition 14 (Algorithm)

Analgorithmis a procedure that describes a finite sequence of steps to be performed in a specified order.

Example 15

Give an algorithm to computePn

i=1xi, where n and x1, x2, . . . , xnare given.

Algorithm

INPUT n, x1, x2, . . . , xn. OUTPUT SU M =Pn

i=1xi.

Step 1. Set SU M = 0. (Initialize accumulator.) Step 2. For i = 1, 2, . . . , n do

Set SU M = SU M + xi. (Add the next term.) Step 3. OUTPUT SU M ;

STOP

95 / 116

師大

Definition 14 (Algorithm)

Analgorithmis a procedure that describes a finite sequence of steps to be performed in a specified order.

Example 15

Give an algorithm to computePn

i=1xi, where n and x1, x2, . . . , xnare given.

Algorithm

INPUT n, x1, x2, . . . , xn. OUTPUT SU M =Pn

i=1xi.

Step 1. Set SU M = 0. (Initialize accumulator.) Step 2. For i = 1, 2, . . . , n do

Set SU M = SU M + xi. (Add the next term.) Step 3. OUTPUT SU M ;

STOP

96 / 116

師大

Definition 14 (Algorithm)

Analgorithmis a procedure that describes a finite sequence of steps to be performed in a specified order.

Example 15

Give an algorithm to computePn

i=1xi, where n and x1, x2, . . . , xnare given.

Algorithm

INPUT n, x1, x2, . . . , xn. OUTPUT SU M =Pn

i=1xi.

Step 1. Set SU M = 0. (Initialize accumulator.) Step 2. For i = 1, 2, . . . , n do

Set SU M = SU M + xi. (Add the next term.) Step 3. OUTPUT SU M ;

STOP

97 / 116

師大

Definition 16 (Stable)

An algorithm is called stable ifsmallchanges in the initial data of the algorithm produce correspondinglysmallchanges in the final results.

Definition 17 (Unstable)

An algorithm is unstable if small errors made at one stage of the algorithm are magnified and propagated in subsequent stages and seriously degrade the accuracy of the overall calculation.

Remark

Whether an algorithm is stable or unstable should be decided on the basis of relative error.

98 / 116

師大

Definition 16 (Stable)

An algorithm is called stable ifsmallchanges in the initial data of the algorithm produce correspondinglysmallchanges in the final results.

Definition 17 (Unstable)

An algorithm is unstable if small errors made at one stage of the algorithm are magnified and propagated in subsequent stages and seriously degrade the accuracy of the overall calculation.

Remark

Whether an algorithm is stable or unstable should be decided on the basis of relative error.

99 / 116

師大

Definition 16 (Stable)

An algorithm is called stable ifsmallchanges in the initial data of the algorithm produce correspondinglysmallchanges in the final results.

Definition 17 (Unstable)

An algorithm is unstable if small errors made at one stage of the algorithm are magnified and propagated in subsequent stages and seriously degrade the accuracy of the overall calculation.

Remark

Whether an algorithm is stable or unstable should be decided on the basis of relative error.

100 / 116

師大

Example 18

Consider the following recurrence algorithm

 x0= 1, x1 = 13 xn+1= 133 xn43xn−1

for computing the sequence of {xn= (13)n}. This algorithm is unstable.

A Matlab implementation of the recurrence algorithm gives the following result.

101 / 116

師大

n xn xn RelErr

8 4.57247371e-04 4.57247371e-04 4.4359e-10 10 5.08052602e-05 5.08052634e-05 6.3878e-08 12 5.64497734e-06 5.64502927e-06 9.1984e-06 14 6.26394672e-07 6.27225474e-07 1.3246e-03 15 2.05751947e-07 2.09075158e-07 1.5895e-02 16 5.63988754e-08 6.96917194e-08 1.9074e-01 17 -2.99408028e-08 2.32305731e-08 2.289e+00 20 -3.40210767e-06 8.60391597e-10 3.955e+03 23 -2.17789924e-04 3.18663555e-11 6.835e+06 27 -5.57542287e-02 3.93411796e-13 1.417e+11 30 -3.56827064e+00 1.45708072e-14 2.449e+14

102 / 116

師大

For any constants c1 and c2, xn= c1

 1 3

n

+ c2(4n) is a solution to the recursive equation

xn= 13

3 xn−1−4 3xn−2 since

13

3 xn−1−4 3xn−2

= 13 3

"

c1 1 3

n−1

+ c24n−1

#

− 4 3

"

c1 1 3

n−2

+ c24n−2

#

= c1 1 3

n−2

 13 3 ·1

3 −4 3



+ c24n−2 13

3 · 4 −4 3



= c1

 1 3

n

+ c24n= xn.

103 / 116

師大

For any constants c1 and c2, xn= c1

 1 3

n

+ c2(4n) is a solution to the recursive equation

xn= 13

3 xn−1−4 3xn−2 since

13

3 xn−1−4 3xn−2

= 13 3

"

c1 1 3

n−1

+ c24n−1

#

− 4 3

"

c1 1 3

n−2

+ c24n−2

#

= c1 1 3

n−2

 13 3 ·1

3 −4 3



+ c24n−2 13

3 · 4 −4 3



= c1

 1 3

n

+ c24n= xn.

104 / 116

師大

Take x0= 1and x1 = 13. This determine unique values as c1= 1and c2 = 0. Therefore,

xn= 1 3

n

for all n.

In computer arithmetic, ˆx0= 1and ˆx1= 0.33 · · · 3. The generated sequence {ˆxn} is then given by

ˆ xn= ˆc1

 1 3

n

+ ˆc2(4n) ,

where ˆc1≈ 1 and |ˆc2| ≈ ε. Therefore, the round-off error is xn− ˆxn= (1 − ˆc1) 1

3

n

− ˆc2(4n) which growsexponentiallywith n.

105 / 116

師大

Take x0= 1and x1 = 13. This determine unique values as c1= 1and c2 = 0. Therefore,

xn= 1 3

n

for all n.

In computer arithmetic, ˆx0= 1and ˆx1= 0.33 · · · 3. The generated sequence {ˆxn} is then given by

ˆ xn= ˆc1

 1 3

n

+ ˆc2(4n) ,

where ˆc1≈ 1 and |ˆc2| ≈ ε.Therefore, the round-off error is xn− ˆxn= (1 − ˆc1) 1

3

n

− ˆc2(4n) which growsexponentiallywith n.

106 / 116

師大

Take x0= 1and x1 = 13. This determine unique values as c1= 1and c2 = 0. Therefore,

xn= 1 3

n

for all n.

In computer arithmetic, ˆx0= 1and ˆx1= 0.33 · · · 3. The generated sequence {ˆxn} is then given by

ˆ xn= ˆc1

 1 3

n

+ ˆc2(4n) ,

where ˆc1≈ 1 and |ˆc2| ≈ ε. Therefore, the round-off error is xn− ˆxn= (1 − ˆc1) 1

3

n

− ˆc2(4n) which growsexponentiallywith n.

107 / 116

師大

Matlab program n = 30;

x = zeros(n,1);

x(1) = 1;

x(2) = 1/3;

for ii = 3:n

x(ii) = 13 / 3 * x(ii-1) - 4 / 3 * x(ii-2);

xn = (1/3)ˆ(ii-1);

RelErr = abs(xn-x(ii)) / xn;

fprintf(’x(%2.0f) = %20.8d, x ast(%2.0f) = %20.8d,’, ...

’RelErr(%2.0f) = %14.4d \n’, ii,x(ii),ii,xn,ii,RelErr);

end

108 / 116

師大

Example 19

Consider the following recurrence algorithm

 x0= 1, x1 = 13 xn+1= 2xn− xn−1

for computing the sequence of {xn= 1 −23n}. This algorithm is stable.

For any constants c1 and c2,

xn= c1+ c2n is a solution to the recursive equation

xn= 2xn−1− xn−2.

109 / 116

師大

Example 19

Consider the following recurrence algorithm

 x0= 1, x1 = 13 xn+1= 2xn− xn−1

for computing the sequence of {xn= 1 −23n}. This algorithm is stable.

For any constants c1 and c2,

xn= c1+ c2n is a solution to the recursive equation

xn= 2xn−1− xn−2.

110 / 116

師大

Take x0= 1and x1 = 13. This determine unique values as c1= 1and c2 = −23. Therefore,

xn= 1 − 2

3n, for all n.

In computer arithmetic, ˆx0= 1and ˆx1= 0.33 · · · 3. The generated sequence {ˆxn} is then given by

ˆ

xn= ˆc1− ˆc2n,

where ˆc1≈ 1 and |ˆc2| ≈ 23. Therefore, the round-off error is xn− ˆxn= (1 − ˆc1) − 2

3 − ˆc2

 n which growslinearlywith n.

111 / 116

師大

Take x0= 1and x1 = 13. This determine unique values as c1= 1and c2 = −23. Therefore,

xn= 1 − 2

3n, for all n.

In computer arithmetic, ˆx0= 1and ˆx1= 0.33 · · · 3. The generated sequence {ˆxn} is then given by

ˆ

xn= ˆc1− ˆc2n,

where ˆc1≈ 1 and |ˆc2| ≈ 23.Therefore, the round-off error is xn− ˆxn= (1 − ˆc1) − 2

3 − ˆc2

 n which growslinearlywith n.

112 / 116

師大

Take x0= 1and x1 = 13. This determine unique values as c1= 1and c2 = −23. Therefore,

xn= 1 − 2

3n, for all n.

In computer arithmetic, ˆx0= 1and ˆx1= 0.33 · · · 3. The generated sequence {ˆxn} is then given by

ˆ

xn= ˆc1− ˆc2n,

where ˆc1≈ 1 and |ˆc2| ≈ 23. Therefore, the round-off error is xn− ˆxn= (1 − ˆc1) − 2

3 − ˆc2

 n which growslinearlywith n.

113 / 116

師大

Definition 20

Suppose{βn} → 0and{xn} → x. If∃ c > 0and an integer N > 0such that

|xn− x| ≤ c|βn|, ∀ n ≥ N,

then we say{xn}convergestox withrate of convergence O(βn), and writexn= x+ O(βn).

Example 21

Compare the convergence behavior of {xn} and {yn}, where xn= n + 1

n2 , and yn= n + 3 n3 .

114 / 116

師大

Definition 20

Suppose{βn} → 0and{xn} → x. If∃ c > 0and an integer N > 0such that

|xn− x| ≤ c|βn|, ∀ n ≥ N,

then we say{xn}convergestox withrate of convergence O(βn), and writexn= x+ O(βn).

Example 21

Compare the convergence behavior of {xn} and {yn}, where xn= n + 1

n2 , and yn= n + 3 n3 .

115 / 116

師大

相關文件