Professional Documents
Culture Documents
Solution Manual For A Friendly Introduction To Numerical Analysis Brian Bradie
Solution Manual For A Friendly Introduction To Numerical Analysis Brian Bradie
Solution Manual For A Friendly Introduction To Numerical Analysis Brian Bradie
Solutions
1.1 Algorithms
1. Use the statistics algorithm from the text to compute the mean, x̄, and the
standard deviation, s, of the data set: −5, −3, 2, −2, 1.
Thus, for the data set consisting of the five numbers −5, −3, 2, −2, and 1, the
mean is x̄ = −1.4 and the standard deviation is s = 2.880972.
2. With n = 4, use the trapezoidal rule algorithm from the text to approximate
the value of the definite integral
Z 1
1
dx.
0 1 + x2
Algorithms 2 2 Section 1.1
Rb
Matching this specific problem to the general pattern a f (x) dx, we see that a = 0,
1
b = 1 and f (x) = 1+x 2 . With n = 4, the trapezoidal rule algorithm yields
Algorithms 3 3 Section 1.1
Let a = 5, x0 = 5, ǫ = 5 × 10−4 , and N max = 10. The first iteration of the square
root algorithm yields
STEP 1: iter = 1
STEP 2: x1 = (5 + 5/5)/2 = 3
STEP 3: |x1 − x0 | = 2 > 5 × 10 −4 , so
STEP 4: x0 = 3
STEP 1: iter = 2
STEP 2: x1 = (3 + 5/3)/2 = 7/3
−4
STEP 3: |x1 − x0 | = 2/3 > 5 × 10 , so
STEP 4: x0 = 7/3
STEP 1: iter = 3
STEP 2: x1 = (7/3 + 15/7)/2 = 47/21
STEP 3: |x1 − x0 | = 2/21 > 5 × 10 −4 , so
STEP 4: x0 = 47/21
STEP 1: iter = 4
STEP 2: x1 = (47/21 + 105/47)/2 = 2207/987
STEP 3: |x1 − x0 | = 2/987 > 5 × 10 −4 , so
STEP 4: x0 = 2207/987
STEP 1: iter = 5
STEP 2: x1 = (2207/987 + 4935/2207)/2 = 4870847/2178309
STEP 3: |x1 − x0 | = 2/2178309 ≈ 9.18 × 10−7 < 5 × 10−4 , so
4. A different scheme for approximating the square root of a positive real number
a is based on the recursive formula
x3n + 3xn a
xn+1 = .
3x2n + a
(a) Construct an algorithm for approximating the square root of a given posi-
tive real number a using this formula.
(b) Test your algorithm using a = 2 and x0 = 2. Allow a maximum of 10
iterations and use a convergence tolerance of ǫ = 5 × 10 −5 . Compare the
STEP 1: iter = 1
STEP 2: x1 = (8 + 12)/(12 + 2) = 10/7
STEP 3: |x1 − x0 | = 4/7 > 5 × 10 −5 , so
STEP 4: x0 = 10/7
In the second iteration, we find
STEP 1: iter = 2
STEP 1: iter = 3
STEP 2: x1 = 1.414213562
STEP 3: |x1 − x0 | ≈ 3.64 × 10 −7 < 5 × 10−5 , so
OUTPUT x1 = 1.414213562
√
Thus, 2 ≈ 1.414213562, which is correct to the digits shown. Observe that
with the same number of iterations (three), the current algorithm produced a
more accurate approximation than the algorithm from the text.
(a) As written, forming the product of ai and bj for each possible combination
of i and j requires n2 multiplications. Summing all n2 terms requires n2 − 1
additions.
(b) Observe that
n n n
! n
XX X X
ai b j = ai bj .
i=1 j=1 i=1 j=1
Using the expression on the right-hand side, the original sum can now be
computed using only 2n − 2 additions and a single multiplication.
7. Let a be a non-zero real number. For any x0 satisfying 0 < x0 < 2/a, the
recursive sequence defined by
xn+1 = xn (2 − axn )
converges to 1/a.
STEP 1: iter = 1
STEP 2: x1 = 0.01(2 − 0.01 · 37) = 0.0163
STEP 3: |x1 − x0 | = 0.0063 > 5 × 10 −4 , so
STEP 4: x0 = 0.0163
In the second iteration, we find
STEP 1: iter = 2
OUTPUT x1 = 0.027027016
Thus, 1/37 ≈ 0.027027016, which is in error by roughly 1.10 × 10 −7.
8. Given two positive integers a and b, the greatest common divisor of a and b
is the largest integer which divides both a and b; i.e., the largest integer n for
which both a/n and b/n are integers.
(a) Construct an algorithm to compute the greatest common divisor of two
positive integers.
(b) How many divisions does your algorithm require?
x · y = x1 y1 + x2 y2 + x3 y3 + · · · + xn yn .
T
(a) Construct an algorithm to compute the inner product of two n-vectors.
(b) Apply your algorithm to calculate the inner product of the vectors
T
x= −3 4 1 2 and y= 1 −3 2 5
Algorithms 8 8 Section 1.1
x = [ −3 4 1 2 ] and y =[ 1 −3 2 5 ]
10. The linear correlation coefficient for n ordered pairs (xi , yi ) is given by the
formula
Pn Pn Pn
n
r= q P i=1 xi yi − ( qi=1 xi ) ( i=1 yi ) .
n Pn 2 Pn P 2
n i=1 xi − ( i=1 xi ) n i=1 yi − ( ni=1 yi )
2 2
end
n · xysum − (xsum)(ysum)
STEP 3: calculate r = p p
n · x2sum − (xsum)2 · n · y2sum − (ysum)2 )
OUTPUT: r
7(239) − (31)(9)
STEP 3: r= p p = 0.987
7(201) − (31)2 · 7(651) − (9)2 )
OUTPUT: r = 0.987
Thus, the linear correlation coefficient of the seven given data pairs is 0.987.
11. The midpoint rule approximates the value of a definite integral using the formula
Z b n
X
f (x)dx ≈ 2h f (xj ),
a j=1
R2
(b) Apply your algorithm to approximate the value of 1 dx/x. Take n = 4.
Compare the approximation obtained from the midpoint rule with the
approximation obtained from the trapezoidal rule.
half the error in the trapezoidal rule approximation obtained in the text.
Aside from the operations needed to evaluate f , the trapezoidal rule algorithm
presented in the text uses 2n + 1 additions/subtractions (one in STEP 1, 2(n − 1)
Algorithms 10 10 Section 1.1
13. Rewrite the algorithm for the trapezoidal rule which was presented in the text to
reduce both the number of additions and the number of multiplications/divisions
by one.
j
(a) For each j, evaluation of the term aj x 0 requires j multiplications (j − 1 to
evaluate the power of x0 and one more to include the coefficient). Thus, to
evaluate the entire polynomial requires
X
n
n(n +
j =1)
2
j=1
Algorithms 11 11 Section 1.1
Based on this form, we can evaluate the polynomial with the following algo-
rithm:
GIVEN: the polynomial coefficients a0 , a1 , a2 , ..., an
value of independent variable x0
the degree of the polynomial n
For Exercises 15 - 18, make use of the fact that when the sum of a convergent
alternating series is approximated using the sum of the first n terms, the error
in P
this approximation is smaller than the magnitude of the (n+1)-st term; i.e.,
if (−1)n an is an alternating series with sum S, then
n−1
X
S− (−1) k ak < an .
k=0
(b) With a tolerance of 5 × 10−3 , it takes 400 terms to produce the estimate
−3
π ≈ 3.1391, which is in error by roughly 2.5 × 10 .
(b) With a tolerance of 5 × 10−7 , ten terms are needed to produce the estimate
−7
1/e ≈ 0.367879189, which is in error by roughly 2.5 × 10 .
(b) With a tolerance of 5 × 10−7 , three terms are needed to produce the estimate
−8
sin(π/10) ≈ 0.309017054, which is in error by roughly 6.0 × 10 .