You are on page 1of 5

EP501 Numerical Methods Homework 2 Solution Due Sep 27, 2013 11:59 pm

1 Finding Roots (30 points)


2
i. f (x) = x + e−x cos x
 2
2
ii. f (x) = x + e−x cos x

For the first function, all methods can converge and find the solution. The iteration steps needed are 42, 7,
6, and 7 for bisection, false position, Newton’s and secant method, respectively. The following figure shows
that Newton’s method has fastest convergence, consistent with its quadratic convergence rate. The Secant
method is a little slower, at super linear rate. Bisection is clearly linear. False position also convergences
very quickly, which is general the case compared with the bisection method. Note in the code how relative
error is calculated for the false position method.

The 2nd function is the square of the first one, so it has the same root but with a multiplicity of 2. Because
the function values are all positive around the root, closed domain methods don’t work. The figure below
shows that both Newton’s and Secant method are linearly convergent. We can also easily use the modify
Newton’s method since we know the multiplicity. The red line in the figure shows the modified Newton’s
method gives quadratic convergence rate (The modified Newton’s method is not required).

1
EP501 Numerical Methods Homework 2 Solution Due Sep 27, 2013 11:59 pm

2 Fixed Point Iteration (40 points)


Find two roots near +1 and -1 of the equation f (x) = x4 + 2x2 − x − 3 = 0 using fixed point iteration
x = g(x). Use the following four g(x) functions.
 41
i. g1 (x) = 3 + x − 2x2
 21
x + 3 − x4

ii. g2 (x) =
2
  12
x+3
iii. g3 (x) =
x2 + 2
3x4 + 2x2 + 3
iv. g4 (x) =
4x3 + 4x − 1
Their derivatives are
1 3
g10 (x) = (3 + x − 2x2 )− 4 (1 − 4x)
4
− 12
1 x + 3 − x4 1 − 4x3

0
g2 (x) =
2 2 2
− 12 (1)
−x2 − 6x + 2

1 x+3
g30 (x) = 2
2 x +2 (x2 + 2)2
4(3x6 + 7x4 − 3x3 − 7x2 − x − 3)
g40 (x) =
(4x3 + 4x − 1)2

The attachment MATLAB code HW2 p2.m gives the following output for each g function and two different
initial values. The initial values are chosen to be close to the root, identified from the plot of the function,
which is also generated by the MATLAB code.
Following are output with initial value x0 = 1.1.

----g1 x0=+1.100000 g1d(x0)=-0.576019


Fixed Point Iteration Method
01 x1=+1.100000000000 x2=+1.138485019524 relerr=3.498638e-02
02 x1=+1.138485019524 x2=+1.115104649323 relerr=2.053639e-02
03 x1=+1.115104649323 x2=+1.129603762231 relerr=1.300247e-02
04 x1=+1.129603762231 x2=+1.120724437712 relerr=7.860566e-03
05 x1=+1.120724437712 x2=+1.126204541581 relerr=4.889787e-03
.....
20 x1=+1.124125357757 x2=+1.124121597103 relerr=3.345405e-06
21 x1=+1.124121597103 x2=+1.124123911272 relerr=2.058646e-06
22 x1=+1.124123911272 x2=+1.124122487220 relerr=1.266810e-06
23 x1=+1.124122487220 x2=+1.124123363528 relerr=7.795487e-07
----g1 x=+1.124123 g1(x)=+1.124123 g1d(x)=-0.615363

g1 (x) gives a convergent iteration. The convergence speed appears to be linear. The derivative is calculated
both at the initial value and at the root. It shows that the |g1 (x)| < 1, which is consistent with the
convergence criterion.

----g2 x0=+1.100000 g2d(x0)=-0.941621


Fixed Point Iteration Method

2
EP501 Numerical Methods Homework 2 Solution Due Sep 27, 2013 11:59 pm

01 x1=+1.100000000000 x2=+1.148020034668 relerr=4.365458e-02


02 x1=+1.148020034668 x2=+1.097958977414 relerr=4.360643e-02
03 x1=+1.097958977414 x2=+1.149933731904 relerr=4.733761e-02
04 x1=+1.149933731904 x2=+1.095748736942 relerr=4.712010e-02
05 x1=+1.095748736942 x2=+1.151987757639 relerr=5.132474e-02
.....
46 x1=+1.223167485374 x2=+0.996176812590 relerr=1.855761e-01
47 x1=+0.996176812590 x2=+1.227066030207 relerr=2.317753e-01
48 x1=+1.227066030207 x2=+0.989939522087 relerr=1.932467e-01
49 x1=+0.989939522087 x2=+1.230767690755 relerr=2.432756e-01
50 x1=+1.230767690755 x2=+0.983916065323 relerr=2.005672e-01
----g2 x=NaN g2(x)=NaN g2d(x)=-1.041258

g2 (x) does not give a convergent iteration, when the maximum iteration step 50 is reached. The derivative
at the initial point is |g2 (x0 )| = 0.9416 < 1. However, when using the root α1 = 1.124123 found with |g1 (x),
we get |g2 (α1 )| = 1.0413 > 0. This explains why g2 (x) does not give a convergent iteration.

----g3 x0=+1.100000 g3d(x0)=-0.249458


Fixed Point Iteration Method
01 x1=+1.100000000000 x2=+1.130158646818 relerr=2.741695e-02
02 x1=+1.130158646818 x2=+1.122607691121 relerr=6.681324e-03
03 x1=+1.122607691121 x2=+1.124503170140 relerr=1.688461e-03
04 x1=+1.124503170140 x2=+1.124027647238 relerr=4.228738e-04
05 x1=+1.124027647238 x2=+1.124146961237 relerr=1.061486e-04
06 x1=+1.124146961237 x2=+1.124117025187 relerr=2.663001e-05
07 x1=+1.124117025187 x2=+1.124124536257 relerr=6.681751e-06
08 x1=+1.124124536257 x2=+1.124122651705 relerr=1.676462e-06
09 x1=+1.124122651705 x2=+1.124123124546 relerr=4.206307e-07
----g3 x=+1.124123 g3(x)=+1.124123 g3d(x)=-0.250903

The convergence rate appears to be linear, and both |g3 (x0 )| and |g3 (α1 )| are less than 1. They are also
smaller than those for g1 (x), which explains why g3 (x) gives a faster iteration than g1 (x).

----g4 x0=+1.100000 g4fd(x0)=-0.052537


Fixed Point Iteration Method
01 x1=+1.100000000000 x2=+1.124747822100 relerr=2.249802e-02
02 x1=+1.124747822100 x2=+1.124123436935 relerr=5.551335e-04
03 x1=+1.124123436935 x2=+1.124123029704 relerr=3.622650e-07
----g4 x=+1.124123 g4(x)=+1.124123 g4d(x)=+0.000001

g40 (α1 ) is very close to zero at the root. Since the g(x) for Newton’s method also has zero derivative at the
root, this suggests that g4 is related to Newton’s method. For Newton’s method, we have

f (x) x4 + 2x2 − x − 3 3x4 + 2x2 + 3


g(x) = x − = x − = = g4 (x). (2)
f 0 (x) 4x3 + 4x − 1 4x3 + 4x − 1

This confirms that g4 (x) actually represents Newton’s method. This explains why the convergence is fastest
among the four g functions.
Following are output with initial value x0 = 0.9.
----g4 x0=-0.900000 g4d(x0)=0.042770
Fixed Point Iteration Method

3
EP501 Numerical Methods Homework 2 Solution Due Sep 27, 2013 11:59 pm

01 x1=-0.900000000000 x2=-0.876569984034 relerr=2.603335e-02


02 x1=-0.876569984034 x2=-0.876053361006 relerr=5.893688e-04
03 x1=-0.876053361006 x2=-0.876053115817 relerr=2.798789e-07
----g4 x=-0.876053 g4(x)=-0.876053 g4d(x)=+0.000000

We start fist with g4 first because we know it is the best method. Indeed it converges quickly and found the
negative root to be α2 = −0.8761.

----g1 x0=-0.900000 g1d(x0)=1.994192


Fixed Point Iteration Method
01 x1=-0.900000000000 x2=+0.832358290058 relerr=1.924843e+00
02 x1=+0.832358290058 x2=+1.250679304486 relerr=5.025733e-01
03 x1=+1.250679304486 x2=+1.029260925609 relerr=1.770385e-01
04 x1=+1.029260925609 x2=+1.175674326239 relerr=1.422510e-01
05 x1=+1.175674326239 x2=+1.089936766857 relerr=7.292628e-02
...
25 x1=+1.124126301205 x2=+1.124121016536 relerr=4.701134e-06
26 x1=+1.124121016536 x2=+1.124124268529 relerr=2.892920e-06
27 x1=+1.124124268529 x2=+1.124122267377 relerr=1.780188e-06
28 x1=+1.124122267377 x2=+1.124123498812 relerr=1.095463e-06
29 x1=+1.124123498812 x2=+1.124122741033 relerr=6.741061e-07
----g1 x=+1.124123 g1(x)=+1.124123 g1d(x)=+1.674818

g1 (x) gives a linear convergent iteration but still reaches the positive root. Examining the figure of g, we
can see g1 has no intersection with y = x near the negative root. In fact the expression of g1 (x) means
that it can only be positive. In other words, x = g(x) is not equivalent to f (x) = 0 when x < 0. We may
considering the negative of g1 ,
1
g1∗ (x) = −g1 (x) = − 3 + x − 2x2 4 (3)
which is equivalent to f (x) = 0 when x < 0. However, the MATLAB output above shows |g1∗ (α2 )| = 1.67 > 1,
this modified g1∗ (x) still will not be able to give a confergent iteration to the negative root.

----g2 x0=-0.900000 g2d(x0)=1.152203


Fixed Point Iteration Method
01 x1=-0.900000000000 x2=+0.849676408993 relerr=1.944085e+00
02 x1=+0.849676408993 x2=+1.290051279309 relerr=5.182854e-01
03 x1=+1.290051279309 x2=+0.871889362287 relerr=3.241436e-01
04 x1=+0.871889362287 x2=+1.283354766711 relerr=4.719239e-01
05 x1=+1.283354766711 x2=+0.886213166954 relerr=3.094558e-01
.....
46 x1=+0.929750016368 x2=+1.261447974843 relerr=3.567604e-01
47 x1=+1.261447974843 x2=+0.929883931298 relerr=2.628440e-01
48 x1=+0.929883931298 x2=+1.261389173508 relerr=3.565017e-01
49 x1=+1.261389173508 x2=+0.929995037644 relerr=2.627216e-01
50 x1=+0.929995037644 x2=+1.261340357227 relerr=3.562872e-01
----g2 x=NaN g2(x)=NaN g2d(x)=+1.052840

Similar to g1 , g2 has no intersection with f (x) therefore the iteration cannot converge to α2 . Also because
the initial condition is now too far away from α1 , the iteration does not converge to α1 either. Also similar
to g2 , the function g2∗ (x) = −g2 (x) won’t give a convergent iteration because |g2 (α2 )| = 1.0528 > 1.

----g3 x0=-0.900000 g3d(x0)=0.482710

4
EP501 Numerical Methods Homework 2 Solution Due Sep 27, 2013 11:59 pm

Fixed Point Iteration Method


01 x1=-0.900000000000 x2=+0.864483059900 relerr=1.960537e+00
02 x1=+0.864483059900 x2=+1.186015087318 relerr=3.719356e-01
03 x1=+1.186015087318 x2=+1.108505359940 relerr=6.535307e-02
04 x1=+1.108505359940 x2=+1.128034607500 relerr=1.761764e-02
05 x1=+1.128034607500 x2=+1.123141186975 relerr=4.338006e-03
06 x1=+1.123141186975 x2=+1.124369350889 relerr=1.093508e-03
07 x1=+1.124369350889 x2=+1.124061225230 relerr=2.740431e-04
08 x1=+1.124061225230 x2=+1.124138536550 relerr=6.877857e-05
09 x1=+1.124138536550 x2=+1.124119138978 relerr=1.725550e-05
10 x1=+1.124119138978 x2=+1.124124005900 relerr=4.329543e-06
11 x1=+1.124124005900 x2=+1.124122784773 relerr=1.086292e-06
12 x1=+1.124122784773 x2=+1.124123091158 relerr=2.725546e-07
----g3 x=+1.124123 g3(x)=+1.124123 g3d(x)=+0.483550

Again g3 has no intersection with f (x) when x < 0, so it does not converge to the negative root. However,
since |g3 (α2 )| = 0.4836 < 1, if one use g3∗ (x) = −g3 (x) for the iteration, it will converge to the negative root
α2 .

3 Wilkinson’s Polynomial (30 points)


See attachment for the MATLAB code. The 20 roots are

m=01 c=9.9999917793887294e-01 f(c)=-1.126782e+01


m=02 c=2.0000156198157151e+00 f(c)=+2.111710e+00
m=03 c=2.9998594654446520e+00 f(c)=-2.186432e-01
m=04 c=4.0007975640057980e+00 f(c)=-4.611206e-02
m=05 c=4.9968260978897669e+00 f(c)=+2.005005e-02
m=06 c=6.0096500526908754e+00 f(c)=+1.052856e-03
m=07 c=6.9780344071819984e+00 f(c)=+3.173828e-03
m=08 c=8.0424468197941703e+00 f(c)=+1.266479e-03
m=09 c=8.9386518013725720e+00 f(c)=+5.798340e-04
m=10 c=1.0077239475245202e+01 f(c)=+6.713867e-04
m=11 c=1.0922760524754798e+01 f(c)=+7.476807e-04
m=12 c=1.2061348198627428e+01 f(c)=+5.798340e-04
m=13 c=1.2957553180205830e+01 f(c)=+1.281738e-03
m=14 c=1.4021965592818001e+01 f(c)=-9.765625e-04
m=15 c=1.4990349947309126e+01 f(c)=-8.041382e-03
m=16 c=1.6003173902110230e+01 f(c)=-6.427002e-02
m=17 c=1.6999202435994203e+01 f(c)=-1.574249e-01
m=18 c=1.8000140534555349e+01 f(c)=+7.296906e-01
m=19 c=1.8999984380184284e+01 f(c)=+1.064062e+01
m=20 c=2.0000000822061129e+01 f(c)=+1.643023e+02

Even though in this code, the error threshold is set to be eps, the smallest possible, the function values at
the first and last few roots are relative much larger than those in the middle. This is because the derivative
of the function at these roots are very large. A small uncertainty on the order of eps can cause a large
deviation from zero in the function value.

You might also like