You are on page 1of 4

NUMERICAL METHODS - 6CCM359A

WEEK 4 TUTORIAL

Exercise 1. Write pseudo-code for the false position method.


Optional: Implement the method in your favorite programming language.
Solution The false position method works by choosing the point
ck =

ak1 f (bk1 ) bk1 f (ak1 )


f (bk1 ) f (ak1 )

and setting ak = ck , bk = bk1 if f (ak1 ) and f (ck ) have the same sign, and ak = ak1 ,
bk = ck if f (bk1 ) and f (ck ) have the same sign.
input: initial guesses a,b with f(a)f(b)<0
function f
tolerance eps
max number of iterations MAX_LOOP
output: approximate zero p of f
p = a
for i = 1 , ... , MAX_LOOP
{
c = ( a * f(b) - b * f(a) ) / ( f(b) - f(a) )
if f(c) == 0
{
print "Found exact solution"
return c
}
else if f(a)*f(c) > 0
{
a = c
}
else
{
b = c
}
if abs( p-c ) < eps
{
print "Found solution with given tolerance"
return c
}
p = c
}
print "Method failed - MAX_LOOP counter exceeded"
1

Exercise 2. The function f (x) = sin(x) has zeros at every integer. Show that
the bisection method on [a, b] with a (1, 0) and b (2, 3) converges to
(i) 0 if a + b < 2
(ii) 2 if a + b > 2
(iii) 1 if a + b = 2.
Solution
(i) Using the bisection method, the first approximation is given by
(.5, 1). Since sin is positive on the interval [ 2 , ] and negative on
c = a+b
2
[, 0], the bisection method converges to a zero in (1, 1). The only zero
in that interval is 0; hence, the limit is 0.
(ii) For a+b > 2 the first approximation c = a+b
(1, 1.5) where sin() negative.
2
Hence, the method converges to a zero in (1, 3), i.e., 2.
(iii) For a + b = 2, c = 1, i.e., an exact solution has been found in the first step.
Exercise 3.
(i) Show that f (x) = + 21 sin x2 has a unique fixed point in [0, 2].
(ii) Estimate (upper bound) the number of iterations needed to find an approximation with absolute error less than 0.01.
(iii) Use the fixed point iteration to find an approximation with error less than
0.01.
Solution
(i) f is C , f [[0, 2]] = [, + 21 ] [0, 2], and f (x) = 14 cos x2 .
Hence, f is a strict contraction with contraction constant 41 and, thus,
has a unique fixed point by the fixed point theorem.
(ii) The initial error e0 satisfies e0 . Since we have an upper bound 14 on the
contraction constant, the error after n iterations is bounded by
1 n
en ( ) e0 = 4n 41n .
4
Hence, we are looking for n such that 41n .01, or
1n

2 ln 10
,
ln 4

which yields
2 ln 10
4.32,
ln 4
i.e., we will definitely have the required accuracy after 5 iterations.
(iii) The first five iterations xj+1 = f (xj ) yield
n1+

j
0
1
2
3
4
5

xj

3.64159265359
3.62604886445
3.62699562244
3.62693879423
3.62694220835

f (xj )
3.64159265359
3.62604886445
3.62699562244
3.62693879423
3.62694220835
3.62694200325

Exercise 4. Consider the sequence given by p0 = 21 and pn = cos pn1 . Generate


the first five terms of the sequence defined by Aitkens method.
Solution If (pn )nN converges to p, then Aitkens 2 method considers the sequence (qn )nN defined by
(pn+1 pn )
(pn )
= pn
2
pn
pn+2 2pn+1 + pn
2

n N qn = pn

which, again, converges to p. Hence, we will have to calculate p1 to p7 .


1
2
p1 = cos p0 0.8775825618903728
p2 = cos p1 0.6390124941652592
p0 =

p3 = cos p2 0.8026851006823349
p4 = cos p3 0.6947780267880062
p5 = cos p4 0.7681958312820161
p6 = cos p5 0.719165445942419
p7 = cos p6 0.752355759421527
This yields
q0 =0.7313851863825818
q1 =0.7360866917130169
q2 =0.7376528713963997
q3 =0.7384692208762632
q4 =0.7387980651735903
q5 =0.7389577109414179
In comparison, it takes until p14 for 0.73 to not change anymore.
Exercise 5. Use each of the following methods to find an approximate solution of
600x4 550x3 + 200x2 20x 1 = 0
in [0.1, 1] with absolute error less than 104 .
(i)
(ii)
(iii)
(iv)

Bisection method
Newtons method
Secant method
False position method

Solution
(i) Bisection method: The error of the nth estimate is given by
ln(10)
n
13.1 iterations. Rounded to 5
0.9 2 . Hence, we need n ln(0.9)+4
ln(2)
digits for printing purposes:
j
0
1
2
3
4
5
6
7
8
9
10
11
12
13

a
0.1
0.1
0.1
0.2125
0.2125
0.2125
0.22656
0.22656
0.23008
0.23184
0.23184
0.23228
0.23228
0.23228

b
c
1.0
0.55
0.55
0.325
0.325
0.2125
0.325
0.26875
0.26875 0.24063
0.24063 0.22656
0.24063 0.23359
0.23359 0.23008
0.23359 0.23184
0.23359 0.23271
0.23271 0.23228
0.23271 0.23250
0.23250 0.23239
0.23239 0.23233

f (a)
1.49
1.49
1.49
0.27293
0.27293
0.27293
0.08051
0.08051
0.03172
0.00722
0.00722
0.00108
0.00108
0.00108

f (b)
229.0
11.898
1.4385
1.4385
0.52433
0.11630
0.11630
0.01735
0.01735
0.01735
0.00506
0.00506
0.00199
0.00045

f (c)
11.8975
1.4385
0.27293
0.52433
0.11630
0.08051
0.01735
0.03172
0.00722
0.00506
0.00108
0.00199
0.00045
0.00032

(ii) Newtons method: We will use Newtons method starting with x0 = 0.1

j
xj
xj xj1
1 0.352542372881
0.252542372881
2 0.258921461964
0.0936209109178
3 0.232964129421
0.0259573325424
4 0.23235325821
0.000610871211526
5 0.23235296475 2.93459732903 1007
(iii) Secant method: 7 iterations
2
3
4
5
6
7
8
j 0 1
xj .1 1 .10582 .11146 .31178 .21954 .23135 .23236 .23235
(iv) False position method: 8 iterations
j
xj
0
.1
1
1
2 .10582
3 .33641
4 .21214
5 .23784
6 .23107
7 .23266
8 .23228
9 .23237

You might also like