Numerical Methods I - Solutions 1

MATH 3241 /EECS 3121 - Suggested Solutions for Practice Problem 1


For ODD number questions you can find the solutions at the back of 
text book.  You need add more details following the hints below.
_________________________________________________________________
_________________________________________________________________

Sec 1.1, no 10:
f(x) = (x+1)^(1/2)                      f(0) = 1
f'(x) = (1/2)(x+1)^(-1/2)               f'(0) = 1/2
f''(x) = (-1/4)(x+1)^(-3/2)             f''(0) = -1/4
f'''(x) = (3/8)(x+1)^(-5/2)             f'''(0) = 3/8

so P_3(x) = 1 +(1/2) x - (1/8)x^2 + (1/16)x^3.

sqrt(0.50) is approx P_3(-0.5) = 0.7109375
The actual value is 0.70710678... so the error is 0.00383072.
(The relative error is 0.0054.. or slightly under one-half percent).
The other parts are just as easy.

________________________________________________________________

Sec 1.1, no 11(a):
f(x) = e^x cos x               f(0) = 1
f'(x) = e^x cos x - e^x sin x  f'(0) = 1
f''(x) = - 2 e^x sin x         f''(0) = 0
f'''(x) = - 2 e^x (sin x + cos x)


Hence P_2(x) = 1+x
and e^x cos x = 1 + x + R_2(x) where
R_2(x) = -(1/3)e^c(sin c + cos c)x^3
and c is some number between 0 and x.

Thus |f(0.5) - P_2(0.5)| = |R_2(0.5)| < = (2/3)e^(0.5)0.5^3 = 0.1373...
(Here we have used |sin c| < =1 and |cos c| <= 1.)
The actual error is much smaller. It is 1 + 0.5 - e^.5 cos .5 = 0.0531...
 
(b) |f(x) - P_2(x)| = |R_2(x)| = | (1/3)e^c(sin c + cos c)x^3 | 
    <= (1/3) e (1+1) 1^3 <= 1.812
(Since 0 < c <1, so e^c <= e, and sin c <=1, cos c <=1.)
____________________________________________________________________

Sec 1.1, no 16:
According to Taylor's theorem, for suitable f,
 
f(b) = f(a) + (b-a)f'(a) + (1/2)(b-a)^2 f''(c) 
where c is a number between a  and b.

Now choose f(x) = sin x, a = 0, b = pi/180, so 
f'(x) = cos x, f''(x) = -sin x, so we get

sin (pi/180) = sin 0 + (pi/180 - 0) cos 0 + (1/2)(pi/180)^2[-sin(c)]

where c is a number between 0 and pi/180.  Thus

sin (pi/180) = 0.0174553 - 0.0001523 sin (c)

So sin (pi/180) is approximately 0.0174553 with an error no bigger in
absolute value than 0.0001523 (Note that |sin (c)| <= 1.)

Another way to say this is that sin (pi/180) is between 
0.0174553 - 0.0001523 and
0.0174553 + 0.0001523

(Check out its "actual" value)
_________________________________________________________________

Sec 1.1, no 17:
42 degrees = 45 degrees - 3 degrees = pi/4 - pi/60 radians.
By Taylor's theorem 
 
cos (pi/4 - pi/60) = cos (pi/4) + (-pi/60) (-sin(pi/4))
              + (1/2!)(-pi/60)^2 (-cos(pi/4))
              + (1/3!)(-pi/60)^3 (sin(pi/4))
              + (1/4!)(-pi/60)^4 (cos(pi/4))
              + (1/5!)(-pi/60)^5 (-sin(c)),
where c is some number between pi/4 - pi/60 and pi/4.
Since |sin x| <=1 for all x, the last term is no bigger in absolute
value than 
            (1/5!)(pi/60)^5 = 3.2795 times 10^(-9)
so if we consider the other five terms only, we will have the
required accuracy. The other five terms give the approximate value
0.7431448 for cos (42 degrees) - we use sin (pi/4) = cos(pi/4) =
1/sqrt(2)

__________________________________________________________________

Sec 1.2, no. 3:

a. Rel err. <= 10^-3, so abs err < = 150*10^-3 = 0.15, so p* must be
between 148.5 and 151.5.

_________________________________________________________________

Sec 1.2, no. 15:

(a) (1/3)x^2 - (123/4)x + 1/6 = 0
    a = 1/3, b = -123/4. c = 1/6
    exact solution: x_1=92.24457963, x_2 = 0.00542037285
    Using four digit to get approximation solution:
    b^2-4ac = (123/4)^2 - 4/(3*6)
            = 945.2
    sqrt(b^2-4ac) = 30.74
    x_1approx = (-b + sqrt(b^2 - 4ac))/(2a) 
              = (123/4 + 30.74)/0.6666
              = 92.24
    x_2approx = 2c/(-b + sqrt(b^2 - 4ac))
              = 0.3332/(123/4 + 30.74)
              = 0.005418

    abs errors:
       | x_1 -x_1approx | = 4.6 x 10^{-3}
       | x_2 -x_2approx | = 2.4 x 10^{-6}
    Rel errors:
       | x_1 -x_1approx |/|x_1| = 5.0 x 10^{-5}
       | x_2 -x_2approx |/|x_2| = 4.4 x 10^{-4}

__________________________________________________________________

Sec 1.2, no. 21:
a. easy

b. Using the first method, we first calculate x0*y1 to be 6.24 and x1*y0
to be 6.25.  (The actual values are 6.2356 and 6.2532.)  The difference is
-0.0100. (Actual is -0.0176.) We have made a big error here. The basic
reason is that we are subtracting nearly equal numbers the "6.2" s cancel
in the two numbers and with only three digits in total all our information
about the two products has to be included in the one remaining digit. This
method gives a bad result. The other one is reasonably satisfactory even
with three digits.

___________________________________________________________________

Sec 1.2, no. 23.

a) use the fomulas given in the question, and four-digit rounding step by step
   it gets the solution 
   x = 2.451, y = - 1.635

    
____________________________________________________________________


Sec 1.3, nos. 1:
1a. The actual answer is 1.5497...
Using 3 -digit arithmetic
we get 1 + 1/4 = 1.25
Then 1+1/4 + 1/9 = 1.25 + .111 = 1.36   *
Adding 1/16 =0.0625 we get 1.42         *
  '    1/25 = 0.0400 "     1.46
       1/36 = 0.0277       1.48         *
       1/49 = 0.0204       1.50         *
       1/64 = 0.0156       1.51         *
       1/81 = 0.0123       1.52         *
      1/100 = 0.0100       1.53

Using the other method we start with 
1/100 + 1/81 = 0.0100 + 0.0123 = 0.0223
adding 1/64 = 0.0156, we get 0.0379  
adding 1/49 = 0.0204, we get 0.0583
adding 1/36 = 0.0277,        0.0860
adding 1/25 = 0.0400          0.126    *
adding 1/16 = 0.0625         0.188      *
adding 1/9 = .111            0.299
adding 1/4 = 0.250           0.549
adding 1/1 = 1.00            1.54       *

The second method gives the better result. There are two kinds of errors
arising here. First, numbers like 1/49 are not dealt with exactly but as
0.0204, for example. But this should lead to about the same inaccuracy in
both methods. Second, when we add two 3-digit numbers and get a number
with four or more digits, we lose accuracy in the chopping.  This happens
six times (indicated by an asterisk) in the first method but only
 three times in the second method

_______________________________________________________________

Sec. 1.3, no 3:
It is not easy to write the general form of the nth derivative for arctan
(x) and so to get the remainder in Taylor's theorem.  However, we can use
here the fact that, for an alternating series whose term decrease in
absolute value to zero, the error involved in stopping at any stage is
less, in absolute value, than the first term omitted.

Here we use 
pi = 4 arctan (1) = 4 P_n(1) + 4(-1)^(n+2)/(2n+1)+ ..., 
where
P_n(1) = 1 - 1/3 + 1/5 - ... + (-1)^(n+1)/(2n-1).
so |4 P_n(1) - pi| <= 4/(2n+1).
So, in part (a), we have to find the smallest value of n for which 
4/(2n+1) is less than 10^(-3). So we want 2n + 1 > 4000 or n > = 2000.
In part (b), we want 4/(2n+1) < 10^(-10), that is, 2n+1 > 40 000 000 000
or n >= 20 000 000 000. 

_________________________________________________________________

Sec. 1.3, no 4:
Again, as in no 3, we use the fact that we are dealing with alternating
series. In the series for arctan(1/2), if we include 5 non-zero terms, the
first (non-zero) term omitted will be (1/2)^11/11 so the error committed
in stopping there will be no more than 0.000044389; if we include
three non-zero terms in the series for arctan(1/3). The error will be no
more than (1/3)^7/7 = 0.0000654. Thus, we can be sure that  the total
error involved in taking
 pi/4 = 1/2 - (1/2)^3/3 + (1/2)^5/5 -(1/2)^7/7 + (1/2)^9/9
    + 1/3 - (1/3)^3/3 + (1/3)^5/5
is no more than 4 (0.00004439 + 0.0000654) = 0.000439 < 10^(-3).
You have to do soem trial and error to see how many terms to take in each
series.
(If we actually do the calculation, we find that we get 
3.141979902... so the actual error is 0.000387.) 
___________________________________________________________________

1.3, no 5:
 
Just taking one term in the series for arctan(1/239) causes an error of no
more than (1/239)^3/3 = 0.000000024. Taking three terms in the series for
arctan(1/4) causes an error of no more than (1/5)^7/7 = 0.000001828.  So
if we approximate pi/4 by 4[1/5 -(1/5)^3/3 +(1/5)^5/5] - 1/239, the error
in pi will be no more than 16(0.000001828) + 4(0.000000024) = 0.0000293...
< 10^(-3).  (If we actually do the calculation, we find that we get
3.141620932 so the actual error is 0.0000282.)

____________________________________________________________________

Sec. 1.3, no 7 (a)(b):
a. sin h /h = 1 - h^2/6 + O(h^4) so the rate is O(h^2).

b. (1/h)(1 - cos h) = h/2 + O(h^3), so the order is O(h).

Note:  FOR more detailed answers, see examples given in class.   
_____________________________________________________________________