Sample - Solution Manual Friendly Introduction To Numerical Analysis Brian Bradie
Sample - Solution Manual Friendly Introduction To Numerical Analysis Brian Bradie
https://www.book4me.xyz/solution-manual-a-friendly-introduction-to-numerical-analysis-bradie/
Algorithms 1
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
1
1
Z
dx.
0 1 + x2
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
https://www.book4me.xyz/solution-manual-a-friendly-introduction-to-numerical-analysis-bradie/
2 Section 1.1
Therefore,
1
1
Z
dx ≈ 0.782794117.
0 1 + x2
The exact value of the integral is π/4, so the absolute error in the trapezoidal rule
approximation is |π/4 − 0.782794117| ≈ 2.604 × 10−3 .
√
3. Use the square root algorithm from the text to approximate 5. Take x0 = 5,
ǫ = 5 × 10−4 and N max = 10.
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
STEP 3: |x1 − x0 | = 2/3 > 5 × 10−4 , 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
Algorithms 3
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
OUTPUT x1 = 4870847/2178309 ≈ 2.236067977
√
Thus, 5 ≈ 2.236067977.
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
performance of this algorithm with the one presented in the text.
4 Section 1.1
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.
Algorithms 5
(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 X n
! n
X X X
ai bj = 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.
(a) Construct an algorithm for approximating the reciprocal of a given non-
zero real number a using this formula.
(b) Test your algorithm using a = 37 and x0 = 0.01. Allow a maximum of 10
iterations and use a convergence tolerance of ǫ = 5 × 10−4 .
6 Section 1.1
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 .
Algorithms 7
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 i=1 xi yi − ( i=1 xi ) ( i=1 yi )
r=q P q .
n Pn 2 Pn Pn 2
n i=1 x2i − ( i=1 xi ) n i=1 yi2 − ( i=1 yi )
8 Section 1.1
end
n · xysum − (xsum)(ysum)
STEP 3: calculate r = p p
n · x2sum − (xsum)2 · n · y2sum − (ysum)2 )
OUTPUT: r
(b) Working sequentially through the steps of the algorithm, we find
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
Algorithms 9
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.
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)
https://www.book4me.xyz/solution-manual-a-friendly-introduction-to-numerical-analysis-bradie/
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.
Algorithms 11
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
k
S − (−1) ak < an .
k=0
12 Section 1.1
Algorithms 13