• No results found

Exercise 0.1 #2. Rewrite the following polynomials in nested form and evaluate at x = 1/2.

N/A
N/A
Protected

Academic year: 2021

Share "Exercise 0.1 #2. Rewrite the following polynomials in nested form and evaluate at x = 1/2."

Copied!
8
0
0

Loading.... (view fulltext now)

Full text

(1)

M348 - Dr. Pencheva - 2pm

1

Textbook Exercises

Exercise 0.1 #2. Rewrite the following polynomials in nested form and evaluate at x = −1/2. (a) P (x) = 6x3− 2x2− 3x + 7

Rewriting the polynomial in nested form:

P (x) = 6x3 − 2x2− 3x + 7 = 7 + x(6x2− 2x − 3) = 7 + x(−3 + x(6x − 2)) And evaluating at x = −1/2: P (−1/2) = 7 − 1 2  −3 −1 2  6 × −1 2 − 2  = 7 − 1 2  −3 −1 2 × −5  = 7 − 1 2× − 1 2 = 29 4 = 7.25 (b) P (x) = 8x5− x4− 3x3+ x2− 3x + 1

Rewriting the polynomial in nested form:

P (x) = 8x5 − x4 − 3x3+ x2− 3x + 1

= 1 + x(8x4− x3− 3x2 + x − 3)

= 1 + x(−3 + x(8x3− x2− 3x + 1))

= 1 + x(−3 + x(1 + x(8x2− x − 3))) = 1 + x(−3 + x(1 + x(−3 + x(8x − 1))))

(2)

And evaluating at x = −1/2: P (−1/2) = 1 −1 2  −3 − 1 2  1 − 1 2  −3 −1 2  8 × −1 2 − 1  = 1 − 1 2  −3 − 1 2  1 − 1 2  −3 −1 2 × −5  = 1 − 1 2  −3 − 1 2  1 − 1 2× − 1 2  = 1 − 1 2  −3 − 1 2× 5 4  = 1 − 1 2 × − 29 8 = 45 16 = 2.8125 (c) P (x) = 4x6− 2x4− 2x + 4

Rewriting the polynomial in nested form:

P (x) = 4x6− 2x4− 2x + 4 = 4 + x(4x5− 2x3− 2) = 4 + x(−2 + x3(x(4x) − 2)) And evaluating at x = −1/2: P (−1/2) = 4 − 1 2 −2 +  −1 2 3 4  −1 2   −1 2  − 2 ! = 4 − 1 2  −2 + −1 8× −1  = 4 − 1 2× − 15 8 = 79 16 = 4.9375

(3)

Exercise 0.2 #4. Convert the following base 10 numbers to binary: (a) 11.25.

Computing directly, as it is relatively simple to represent in binary: (11.25)10 = (11)10+ (0.25)10= (1011.)2 + (.01)2 = (1011.01)2

(b) 23.

Via repeated multiplication by 2...

2 × 2 3 = 1 3+ 1 2 × 1 3 = 2 3+ 0 2 × 2 3 = 1 3+ 1

Note that the third step is the same as the first step, so this is an infinite binary number:

2 3



10 = (0.10)2.

(c) 35.

Via repeated multiplication by 2...

2 × 3 5 = 1 5+ 1 2 × 1 5 = 2 5+ 0 2 × 2 5 = 4 5+ 0 2 × 4 5 = 3 5+ 1 2 × 3 5 = 1 5+ 1

Note that the fifth step is the same as the first step, so this is an infinite binary number:

3 5



(4)

(d) 3.2.

Splitting the number into a whole and fractional component, we can see that (3)10 =

(11)2; we compute the fractional component with repeated multiplication:

2 × 1 5 = 2 5+ 0 2 × 2 5 = 4 5+ 0 2 × 4 5 = 3 5+ 1 2 × 3 5 = 1 5+ 1

So the fractional component is the repeating fraction (0.2)10 = (0.0011)2. Thus, the

overall representation is (3.2)10 = (11.0011)2.

(e) 30.6.

Splitting the number into a whole and fractional component, we can see that (30)10 =

(11110)2, and from part (c) that (0.6)10 = 35



10 = (0.1001)2, such that (30.6)10 =

(11110.1001)2.

(f) 99.9.

Splitting the number into a whole and fractional component, we can see that (99)10 =

(1100011)2; we compute the fractional part using multiplication by 2:

2 × 0.9 = 0.8 + 1 2 × 0.8 = 0.6 + 1 2 × 0.6 = 0.2 + 1 2 × 0.2 = 0.4 + 0 2 × 0.4 = 0.8 + 0 2 × 0.8 = 0.6 + 1

The sixth step is a duplicate of the second step, so this is a repeating fraction and (0.9)10= (0.11100)2. Thus, (99.9)10 = (1100011.11100)2.

(5)

Exercise 0.4 #2. Find the roots of the equation x2+ 3x − 8−14= 0 with three digit accuracy.

Using the quadratic equation, the two roots equal r1 = 1 2  −3 +√9 + 4 · 8−14 r 2 = 1 2  −3 −√9 + 4 · 8−14

Noting that 8−14≈ 2.2737368 × 10−13, we can factor out the negative and compute r

2 directly,

since we’re not subtracting numbers which are close to each other: r2 = −

1 2



3 +p9 + 4 · (2.2737368 × 10−13)≈ −3.00

If we were to naively try to compute r1, however, we would be subtracting 3 from a number

very close to three, resulting in loss of accuracy and a result of 0 instead of a result with three significant figures. Thus, we apply the conjugate trick:

r1 = 1 2  −3 +√9 + 4 · 8−14 = 1 2 (−3 +√9 + 4 · 8−14)(−3 −9 + 4 · 8−14) (−3 −√9 + 4 · 8−14) = 1 2  9 − (9 + 4 · 8−14) −3 −√9 + 4 · 8−14  ≈ −4 · 8 −14 −12.000 ≈ 7.58 · 10 −14

Exercise 0.4 CP #4. Evaluate the quantity √c2+ d − c to four correct significant digits, where

c = 246886422468 and d = 13579.

Directly computing this quantity would result in significant loss in precision since √c2+ d is

very close to c; instead, we perform the conjugate trick: √ c2+ d − c = ( √ c2+ d − c)(c2 + d + c) √ c2+ d + c = c2+ d − c2 √ c2+ d + c = d √ c2+ d + c

Plugging in the values of c and d then yields √

(6)

Exercise 0.5 #6.

(a) Find the Taylor polynomial of degree 4 for f (x) = x−2 about the point 1. First, we compute the derivatives of f (x):

f0(x) = −2x−3 f00(x) = 6x−4 f000(x) = −24x−5 f(4)(x) = 120x−6 Then, we can write out the Taylor polynomial at x0 = 1:

P4(x) = f (1) + f0(1) · (x − 1) + f00(1) 2! · (x − 1) 2+f 000(1) 3! · (x − 1) 3 +f(4)(1) 4! · (x − 1) 4 = 1−2+ (−2(1)−3)(x − 1) +6(1) −4 2 (x − 1) 2+−24(1) −5 6 (x − 1) 3+ 120(1) −6 24 (x − 1) 4 = 1 − 2(x − 1) + 3(x − 1)2− 4(x − 1)3+ 5(x − 1)4

(b) Use the result of (a) to approximate f (0.9) and f (1.1).

f (0.9) ≈ 1 − 2(0.9 − 1) + 3(0.9 − 1)2− 4(0.9 − 1)3+ 5(0.9 − 1)4 = 1.2345 f (1.1) ≈ 1 − 2(1.1 − 1) + 3(1.1 − 1)2− 4(1.1 − 1)3+ 5(1.1 − 1)4 = 0.8265

(c) Use the Taylor remainder to find an error formula for the Taylor polynomial. Give error bounds for each of the two approximations made in part (b). Which of the two approxima-tions do you expect to be closer to the true value?

The remainder term for the fourth degree Taylor polynomial is R4(x) = −6(x − 1)5;

thus, we can bound the error to be

|P4(x) − f (x)| ≤

6(x − 1)5

For x = 0.9, the error is thus less than |6(0.9 − 1)5| = 0.00006. Similarly, for x = 1.1,

the error is less than |6(1.1 − 1)5| = 0.00006. Since x grows rapidly around x = 0, I would expect x = 1.1 to be the more accurate estimation.

(d) Use a calculator to compare the actual error in each case with your error bound from part (c).

The absolute error, according to the calculator, for x = 0.9 is 1.2345 − 1.234567901 ≈ 0.00006, which is indeed similar to the above error bound. Similarly, the absolute error

(7)

2

Coding Exercise

1 // S o l v e ax ˆ2 + b x + c = 0 f o r r e a l and i m a g i n a r y r o o t s . 2 #include <i o s t r e a m > 3 #include <cmath> 4 #include <c s t d l i b > 5 6 s t r u c t complex num { 7 double r e a l , imag ;

8 complex num ( double r , double i ) : r e a l ( r ) , imag ( i ) {} 9 } ;

10

11 const double EPS = 1 e −16; 12

13 i n t q u a d r a t i c f o r m u l a ( double a , double b , double c , complex num& f i r s t , complex num & s e c o n d ) {

14 i f ( s t d : : abs ( a ) < EPS) return −1; 15 16 double d i s c r i m i n a n t = b∗b − 4∗ a ∗ c ; 17 18 i f ( d i s c r i m i n a n t > 0 . 0 ) { 19 // I f d i s c r i m i n a n t i s p o s i t i v e , t h e n b o t h r o o t s a r e r e a l . 20 f i r s t = complex num (( −b + s q r t ( d i s c r i m i n a n t ) ) / ( 2 ∗ a ) , 0 . 0 ) ; 21 s e c o n d = complex num (( −b − s q r t ( d i s c r i m i n a n t ) ) / ( 2 ∗ a ) , 0 . 0 ) ; 22 return 2 ; 23 } e l s e i f ( s t d : : abs ( d i s c r i m i n a n t ) < EPS) { 24 // I f d i s c r i m i n a n t ˜ 0 , t h e n one r e a l r o o t . 25 f i r s t = complex num(−b / ( 2 ∗ a ) , 0 . 0 ) ; 26 return 1 ; 27 } e l s e { 28 // O t h e r w i s e , two i m a g i n a r y r o o t s . 29 f i r s t = complex num(−b / ( 2 ∗ a ) , −s q r t (− d i s c r i m i n a n t ) / ( 2 ∗ a ) ) ; 30 s e c o n d = complex num(−b / ( 2 ∗ a ) , s q r t (− d i s c r i m i n a n t ) / ( 2 ∗ a ) ) ; 31 return 2 ; 32 } 33 } 34 35 i n t main ( ) { 36 double a , b , c ; 37 s t d : : c o u t << ” S o l v e ax ˆ2 + bx + c = 0 f o r r e a l r o o t s . \ nEnter a , b , c : ” ; 38 s t d : : c i n >> a >> b >> c ; 39 40 complex num r 1 ( 0 . 0 , 0 . 0 ) , r 2 ( 0 . 0 , 0 . 0 ) ; 41 i n t n u m r o o t s = q u a d r a t i c f o r m u l a ( a , b , c , r1 , r 2 ) ; 42

(8)

M348 - Dr. Pencheva - 2pm

3

Coding Input + Output

1 ===== 2 I n p u t 3 ===== 4 5 2 −3 4 6 7 ====== 8 Output 9 ====== 10 11 S o l v e ax ˆ2 + bx + c = 0 f o r r e a l r o o t s . 12 E n t e r a , b , c : 2 −3 4 13 14 Root 1 : 0 . 7 5 + −1.19896 i 15 Root 2 : 0 . 7 5 + 1 . 1 9 8 9 6 i

References

Related documents