Vous êtes sur la page 1sur 20

Joseph Wheatland

C3 Coursework
In this coursework I will be using three different methods to solve an
equation. These are the:
Change of sign method which involves a decimal search
Newton-Raphson method
Rearrangement of f(x) = 0 to x = g(x)
I will use each of these methods to find a success and a failure and at the
end will identify the practicalities of each method in different situations
compared to each other.

Change of sign method


If we were to graph an equation with roots to the equation f(x) = 0, it
would be seen that the equation will cross or touch the line. When it
crosses the x axis, the value of f(x) = 0 will change from a positive to a
negative number between two intervals either side of the actual root. We
can keep narrowing the intervals to keep getting closer to the actual root
value but the value will never actually be met, which is why I am going to
test this method to three decimal places. I will then repeat this between
this two integers until a change of sign occurs again.
By using a decimal search where integers are chosen to put into the
equation f(x) = 0, I can find two values that lay either side of the actual
route.

Example
I will use this method to solve the equation 0.5x+2x30x+24.2 = 0.
To do this I will find the values of f(x) = 0.5x+2x30x+24.2 and detail
where the value of the f(x) changes from a positive value to a negative. As
seen in the graph plotted in autograph, there are three roots for this
equation. I will be searching for the second root.
Consecutive integers take the place of x in the function. If the function of
0 is used we arrive at the answer 24.2:
f(0) = 0.5x0+2x030x0+24.2 = 24.2
Equation 1
1

Joseph Wheatland

With the function of 1 we can see that the answer is now negative
(Equation 2). This means there is a root in this interval. We can now
narrow down this search to locate the root in the 0-1 range.
f(1) = 0.5x1+2x130x1+24.2 = -3.3
Equation 2

f(0) =

f(1) = -3.3

As the f(0) is positive and f(1) is negative this tells us the graph must
cross the x axis between 0 and 1. We can now narrow down one of the
roots to being in the range (0, 1)
Figure 1: f(x) = 0.5x+2x30x+24.2
It is now possible to do a decimal search in which I will split the interval
into ten and will again calculate the values of f(x) for the values of x in the
0-1 interval until a change in sign occurs. This step is repeated until the
accuracy comes to four decimal places and the number can be accurately
rounded to 3 decimal places.

Joseph Wheatland

Step 1

Step 2

x
f(x)
f(x)
1
-3.3
160.7
168.2
0.9
0.815
161.7
5
144.2
f(x)
Root in interval
0.8
118.7
1.736
1.736 (0.8,0.9)
88.2
1.4779
21
55.7
1.2204
24.2
84-3.3
0.9636
Root in interval (0,1)
-23.8
94
as there is a change of
-34.3
0.7075
sign
-31.8
52
where the line crosses
-13.3
0.4520
x
63
0.1972 Root in interval
0.86
28
(0.86,0.87)
0.87
Step 4
x
f(x)
Step 0.0569
5
0.1972
3
0.86
28
0.1717
0.861
81
0.1463
0.862
4
0.1209
0.863
06
0.0954
0.864
78
0.0700
0.865
57
0.0446
0.866
43
0.0192 Root in interval
0.867
35
(0.867,0.868)
0.0061
0.868
7
x
-7
-6
-5
X -4
0.8 -3
-2
0.81
-1
0.820
1
0.832
3
0.844
5
0.85

Joseph Wheatland

x
0.867
0.8671
0.8672
0.8673

Step 5

0.8674
0.8675
0.8676
0.8677
0.8678

f(x)
0.0192
35
0.0166
95
0.0141
54
0.0116
14
0.0090
74
0.0065
34
0.0039
94
0.0014
54
0.0010
9

Root in interval
(0.8677,0.8678)

This data has split the values of x into equal intervals so as to get the
degree of accuracy as desired (4 decimal places). We can now diagnose
that f(x) = 0 for 0.8677 < x < 0.8678. This means that the value of the
root is 0.868 (3 d.p) and the former value of f(x) describes the error
bounds of the answer. If we were to again search for a change of sign
between 0.8677 and 0.8678 then it would yield us a more accurate
answer. Our error bound proves our answer is not the definitive one.

Joseph Wheatland
Interval (0.8677, 0.8678)

f(0.8677)
is
POSITIVE

f(0.8678)
is
NEGATIVE

Figure 2: f(x) = 0.5x+2x30x+24.2

[0.8677,0.8678]
The decimal search method I undertook was a success as the function
crosses the x axis between the values of 0.8677 and 0.8678 (figure 2).
When the x axis is intersected, f(x) = 0. Therefore, as the value of
f(0.8677) is positive and the value of f(0.8678) is negative, we know that
there is an intersection trapped between these two points and hence a
root.

Failure of the change of sign method


In some cases this method will fail when there are two or more roots in
close proximity in an integer range. If this is the case, then when we do
the integer search only one change of sign may be noticed and roots
could be overlooked. Without the help of a graph we could miss them
altogether and the method would be a failure as not all the roots would
have been found.
Im using the equation 0.5x+2x30x+59 = 0 to find a failure using the
change of sign method. To do this I will find the values of the function f(x)
= 0.5x+2x30x+59 which have an intersection between them and
therefore a change of sign. With an integer search it appears as if there
are no roots between these
values as the sign
x
f(x)
0
59
remains positive throughout
and doesnt change
1
2
3 5
4
5

31.5
11
0.5
3
21.5

Joseph Wheatland

(figure 3). But as we can see on the graph between three and four there
are two roots. It is not picked up by this method as the sign changes back
to positive in the same interval.
Figure 3: f(x) = 0.5x+2x30x+59
As the two roots havent been picked up with the decimal search and a
success is only a success when all the roots can be found with the

At f(3) the sign


is positive

Integer search
doesnt pick up
these two roots

At f(4) the sign


is positive too

method, this method has failed in this example.


Newton Raphson
The newton Raphson method uses an iterative formula to calculate new
values of x which become more accurate to the actual value of the root.
This iteration works by finding the point at which a tangent to the curve
crosses the x axis. This new value of x is inputted into the iterative
formula and will find a tangent which crosses the x axis closer to the
actual root each time.
f (x n )
The iterative formula used can be generalised to xn+1 = xn - '
f (x n)
The starting point for the formula is known as x0 which is an integer which
lays near the root you are attempting to find. Given this initial integer
estimate, we can use this numerical method to find an estimate to the
root.
Let f(x) = x+27x+5x2.4. The equation f(x) = 0 has two roots (figure 4)
between [-1,0] and [0,1]. We will find both of the roots using the Newton
Raphson method starting with the right root ([0,1]).
x
-3
-2
-1
0
6
1
2

f(x)
198.6
87.6
18.6
-2.4
30.6
123.6

The table of integers for x


below indicates a change
of sign twice which leads
us to the conclusion that
there are two roots.

Joseph Wheatland

Figure 4: f(x) = x+27x+5x2.4


To begin this method it first requires an estimate for the root. This value
(x0) will be 0 as it lies reasonably close to the root. Therefore:
x0 = 0
f(x) = x+27x+5x2.4
f(x) = 3x2+54x+5.
This can be substituted into the general formula in place of xn as follows:
Xn+1 = xn -

X 1 = x0 -

f ( x0 )
f ' ( x 0)

= Xn+1 = xn -

x 30 +27 x 20 +5 x0 2.4
3 x 20+ 54 x 0+5

x 3n +27 x 2n +5 xn 2.4
3 x 2n+ 54 x n+5
0327 02+ 5 02.4
3 0 2+54 0+5

=0-

= 0.48

Now that we have a value for x1 this can be substituted into the iterative
formula again to give out another answer closer to that of the root.
Instead of x0 we now substitute it with x1, and the x1 at the beginning of
the formula becomes an x2 as it will find the second iteration.
3

x2 = x1 -

x 1 +27 x 1+ 5 x 12.4
2
3 x 1+54 x1 +5

= 0.48 -

0.48 27 0.48 + 5 0.482.4


2
3 0.48 +54 0.48+5

0.277
While this process can be repeated to achieve a greater accuracy it is
much easier to use software to calculate the values of x3 etc. as it will find
better values quickly with much less rounding error.

Joseph Wheatland

As each new value of xn


is put into the formula,
the tangent crosses the
x axis closer to the root.
The answer becomes
more accurate.

xn

diagram for f(x) =

0
0.4799
9
0.2797
1
0.2240
12
0.2190
14
0.2189
73
0.2189
73
0.2189
73
0.2189
73

change in
xn
0.479999
982
0.200289
505
0.055698
736
0.004997
567

Figure 5:
Newton
Raphson
tangent
x+27x+5x2.4

The graph illustrates that the


line converges
towards the root very rapidly.
It has only taken
eight iterations to find the
exact route and after
five the digits remained fixed
to six decimal places.
4.07E-05
Starting at 0 (xo)in figure 5,
this graph illustrates
how a line is created which
shoots towards the
2.70E-09
curve up or down and creates
a tangent which then
2.78E-17
shoots off to the x axis. This
point now becomes
x1. The line shoots to the
curve of y= f(x)
0
again and another tangent
forms which shoots
of to the x axis. When this crosses the x axis it is closer to the root and
more accurate to the roots real value. This point is known as x2. This
process repeats and will get more accurate each time. As the iterations
occur, the change in xn becomes less and less as it reaches closer towards
the root, until it is miniscule or reaches zero. This means the method has
found when the f(x) = 0 and hence the root. The line in this case is
converging to a value near 0.218973.
The root between [0,1] is 0.21897 to five significant figures in this case
with the solution bounds of 0.218965<x<0.218975. We know the root is
between these two values as we evaluate f(0.218965) and f(0.2189750)
for a change of sign.

X
X
X
0
3
1
2

Joseph Wheatland

F(0.218965) = -0.000143453025
F(0.218965) = 2.62292106E-005

0.21897 0.000005

The change of sign means there is definitely a root in between the values
and both of these numbers round to 0.21897 so we can say for certain this
is the answer to this root to five significant figures.
There is one more root that lies between [-1,0] that still needs to be found.
Again the same method will be used as before but the value of x0 will be
changed to -1 as it is closer to this root and will find it in fewer iterations.
We can see that the method has found the root with ease in only five
Curve of
y=x+27x+5x2.4

X
0

iterations once
root as -0.40881 to five

Newton Raphson method


A failure in the case of the
method can be defined when
diverges away from the
starting integer or when a

again.

Xn
0.59565217
4
0.44278177
5
0.41042812
6
0.40881290
9
0.40880885
3
0.40880885
3

The iteration gives the


significant figures.
change in
xn
0.404347
826
9 fixed
0.152870
399
figures
0.032353
649
0.001615
216
4.06E-06
2.56E-11

failure
newton Raphson
either the line
closest root from the
different root is found

Joseph Wheatland

than the one we are searching for. This could happen due to the gradient of the
tangent being very close to zero and not reaching the x axis for a long time as it
has a steep crossing point or the function is discontinuous and the tangent is
formed but the new value of xn doesnt hit the curve again.
Let f(x) = (2x3-4x2+1)1/3 (Figure 5.1) I will attempt to find the root on the far right
in the interval [1,2] in this example for the equation f(x) = 0.

Figure 5.1: f(x) = (2x3-4x2+1)1/3


If we take x0 to equal 2 then the expected outcome would be for the root on the
left of this number to be found. However, due to a steep x axis where the line
crosses the turning point the tangent is thrown off from where it should go and
the x1 value is now on the left of the root (figure 5.2). When the line goes from
the x2 number to x3 the intersection of the x axis is further away from the root we
are searching for too. As there is a very low gradient when the line shoots
vertical towards the line from x3, the line now diverges into infinity in the
opposite
direction from the local root.
X4

X4

X3
X1

X0

X2

Figure
The line first goes onto the other
side of the root we are looking for.

5.2
x

change

10

The negative value of the


intersection at the x axis show that
a large divergence away from our
root has occurred

Joseph Wheatland

1.6250
01
2.6593
33
1.1952
28
2.7405
8

in xn
0.37499
909
1.03433
18
1.46410
49
3.93580
32

X = g(x) method
This third method is known at the x = g(x) method which involves
rearranging the equation f(x) = 0 to x= g(x). This new function can then
be used as an iterative formula. When using this method, the function y =
g(x) is plotted against y=x and the points at which these points intersect
will now satisfy the equation f(x) = 0.
I am going to use the x = g(x) method to solve 2x -3x-2x +0.7=0 so let
f(x) = 2x -3x-2x +0.7=0 (figure 6).

Figure 6: f(x) = 2x -3x-2x +0.7


To do this I will use the iteration xn+1 = g(xn) where g(x) is a
rearrangement of the equation 2x -3x-2x +0.7=0 into the form x = g(x).
2x = 2x3-3x2+0.7
X = (2x3-3x2+0.7)/2
Xn+1 = (2xn3-3xn2+0.7)/2

Adding the 2x onto one side


allows us two then divide by
two to leave an x on one side.
This leaves the formula in the
new x = g(x) form.

The x = g(x) iterative formula now becomes Xn+1

= (2xn3-3xn2+0.7)/2 in which a new number is


created with each iteration and substituted
back into the formula for a more accurate
11 each time.
answer

Joseph Wheatland

An integer search can be used now to see which number to use for the
starting value of this formula (x0). In figure 7 there are three turning
points which signifies there are three roots. I am going to focus on the root
between [0,1] so I will make x0 = 0
x
-1
0
1
2
3

f(x)
-2.3
0.7
-2.3
0.7
21.7

Figure
7

This method
Raphson
be found by

uses an iterative formula just like the newton


method. Using x0 = 0 the first iteration can
substituting into the formula

X1 = (2x03-

3x02+0.7)/2 = (2x03-3x02+0.7)/2 = 0.35

X2 = (2x13-3x12+0.7)/2 = (2x0.353-3x0.352+0.7)/2 = 0.209125


As this is an iterative formula that repeats its steps it is once again much
quicker to use software to figure out further iterations. Figure 8 shows
the equations y = x and y = g(x) plotted against each other with the
original y =f(x) also in view. The two latter functions cross at the same x
value as the middle root in the equation f(x) = 0. This is because the

Y=
x
Y=
g(x)

Y=
f(x)

functions
each
Figure 8:
g(x) =

are

just rearrangements of
other.
y = f(x) = 2x -3x-2x +0.7, y =
(2x3-3x2+0.7)/2, y = x

12

Joseph Wheatland

x
0.35
0.209125
0.293545821
0.24604087
0.274090192
0.257902994
0.267383216
0.261875561
0.2650909
0.263219004
0.264310564
0.263674645
0.264045323
0.263829323
0.263955213
0.26388185
0.263924605
0.263899688
0.26391421
0.263905747
0.263910679
0.263907805
0.26390948
0.263908504
0.263909072
0.263908741
0.263908934

change in xn
0.35
0.140875
0.084420821
0.047504951
0.028049322
0.016187198
0.009480222
0.005507655
0.003215338
0.001871896
0.001091559
0.000635919
0.000370678
0.000215999
0.000125889
7.34E-05
4.28E-05
2.49E-05
1.45E-05
8.46E-06
4.93E-06
2.87E-06
1.68E-06
9.76E-07
5.69E-07
3.32E-07
1.93E-07

Now that weve continued with several more iterations


there are six fixed figures for the value of the root. The
value can be rounded to 0.26391 (5 sig. figures). We can
check that there actually is a root near this value by
creating solution bounds and checking for a change of
sign between 0.263905 and 0.263915.
F(0.263905) = 1.22284989E-005
F(0.263915) = -1.94271918E-005
There is a change of sign indicating a root lies between
these numbers and both of these numbers round to
0.26391 so this is the correct root to five significant
figures.

There are six


fixed significant
figures

If we now go back to our graph displaying the cobweb convergence the


pattern is relatively simple to spot the pattern the line takes. The initial
integer estimate of 0 (bottom left of figure 9) is followed up the curve to
the curve y = g(x) and then a horizontal line leads right to the y = x line
as part of the first iteration. The x coordinate of this point is now x1. The
line goes vertical towards the y = g(x) line again and repeats the same
pattern in the next iteration. When the horizontal line drawn reaches the
y=x curve again, this point can be known as x2. Ultimately the line
converges towards the point where y = x and y = g(x) cross which is the

13

Joseph Wheatland

same x coordinate as where the equation f(x) = 0 as the root we are


looking for.

Root of f(x) =
0
X1
X3

X2

Y = x has
gradient of 1

Fig

X0

Y=g(x) line
steeper than y
=x

ure 9

The

reason
for the
cobweb like shape is due to the
magnitude of the root for g(x) when calculated at the root.
When the value of g(x) lies in the bounds -1 < g'(x) <0, the
line
will converge on the root with the cobweb effect. If the root
was higher than zero a staircase pattern would occur instead. Anything
below -1 or above 1 will lead to a failure. In the case of this graph the line
y = x has a gradient of one. The blue line is steeper than the red line
which means that the g(x) lies within the bounds -1<g(x)<0 and forms
the cobweb effect.
Failure of the x = g(x) method
Normally the line used to visualise this method will converge in either a
staircase or cobweb towards an intersection between the equation y = x
and y = g(x) if it is successful. However a failure will do the exact
opposite. It would diverge away from the point of intersection and shoot
off into infinity as it cant reach a point on a curve. Failure would also
constitute finding the wrong root which is not the closest root to the
starting integer.
I am going to once again rearrange my equation f(x) = 0 into the form x =
g(x).

14

Joseph Wheatland

As the roots are found by the equation y = 2x -3x-2x +0.7, I will


x
rearrange this into the form x=( 3x +0.35)1 /2 . The iteration for this

3
1/2
equation is xn+1 = (xn xn +0.35) .
I will choose a different root to work on this time between the integers [2,-1]. The intersection is nearest to the integer -2 so I will make the value
of x0 equal -2. At first glance (figure 10) it is clear to see that the gradient
of the equation y = g(x) is much higher than that of y = x which has a
gradient of 1. This means that g(x)>1; we would expect the line to
diverge away from the intersection in a staircase like pattern. This isnt
too clear to see however as after the line hits y = x for the second time, it
tries to go vertical but shoots to infinity. The line visualising x = g(x) is
very steep so the line created will not reach it. The graph does in fact
diverge away from the intersection as expected (in a staircase pattern)
therefore. The table below shows that the graph is not converging at all
towards the desired too and is in fact moving further away with each
iteration in the interval [-2,-1].

X0
Y=x

X1

X2

Y=
g(x)

Figure 10
2x -3x2x +0.7

x
0
1
2

-2
-2.825
9.685

-449.2

-23.3
-62.682
1516.82
181884169.
8

We know that the g(x) = (xx+0.35)1/2 so therefore:


2
3 x 1
g(x) = 2 3
7
x x +
The value for x is the root we
30

found earlier.

15

Y=f(
x)

Joseph Wheatland

3(0.26391)21
g(x) =

7
30
The value of g(x) is below -1 so a cobweb diverging pattern is formed as
we expected.
2

(0.26391)3(0.26391)+

Comparison of the methods


Each method has its own benefits in different situations and now Ill
compare them by selecting a previously used equation and completing it
using all three methods. In finding a success for the x = g(x) method I
used the equation 2x -3x-2x +0.7=0. Im going to use each method to
solve the root which lies between the integers [0,1].
Decimal search

n
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

x
0
0.1
0.2
0.3
0.21
0.22
0.23
0.24
0.25
0.26
0.27
0.261
0.262
0.263
0.264
0.2631
0.2632
0.2633
0.2634
0.2635
0.2636
0.2637
0.2638
0.2639
0.264
0.2639
1

f(x) = 2x -3x-2x
+0.7
0.7
0.472
0.196
-0.116
0.166222
0.136096
0.105634
0.074848
0.04375
0.012352
-0.019334
0.009196162
0.006037456
0.002875894
-0.000288512
0.002559581
0.00224324
0.00192687
0.001610472
0.001294046
0.000977591
0.000661108
0.000344596
2.80562E-05
-0.000288512
-3.59931E-06

16

Joseph Wheatland

0.2639
01
0.2639
02
0.2639
03
0.2639
04
0.2639
05
0.2639
06
0.2639
07
0.2639
08
0.2639
09

26
27
28
29
30
31
32
33
34

The change of sign method


has taken 34 iterations to trap
the root between 0.263908
and 0.263909. This means
that the value of the root in
the interval [0.1] is 0.26391 to
five significant figures.

2.48907E-05
2.17252E-05
1.85596E-05
1.53941E-05
1.22285E-05
9.06294E-06
5.89738E-06
2.73182E-06
-4.33743E-07

Newton Raphson
n

x
0
1
2

0
0.35
0.26627
0.26391
1
0.26390
9
0.26390
9

3
4
5

xn+1 = 2x -3x-2x +0.7 /


6x^2-6x-2
0.350000336
0.266270398
0.263911335
0.263908863
2.64E-01
2.64E-01

The root is close to 0.26391 so we will check to see if it is trapped


between 0.26390 and 0.26391 in five iterations.
F(0.26390) = 2.8056238E-005
F(0.26391) = -3.59931106E-00
The value of the root is between these two numbers so we can say that the root is
0.26391 to five significant figures.
X = g(x)
x

n
0
1
2
3

0.35
0.2091
25
0.2935
46
0.2460
41

change in
xn
0.35
0.140875
0.084420
821
0.047504
951

The root has been found as


0.26391 to five significant
figures after 23 iterations. The
root is trapped between
0.26390 and 0.26391.

17

Joseph Wheatland

4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

0.2740
9
0.2579
03
0.2673
83
0.2618
76
0.2650
91
0.2632
19
0.2643
11
0.2636
75
0.2640
45
0.2638
29
0.2639
55
0.2638
82
0.2639
25
0.2639
0.2639
14
0.2639
06
0.2639
11
0.2639
08
0.2639
09
0.2639
09

0.028049
322
0.016187
198
0.009480
222
0.005507
655
0.003215
338
0.001871
896
0.001091
559
0.000635
919
0.000370
678
0.000215
999
0.000125
889
7.34E-05
4.28E-05
2.49E-05
1.45E-05
8.46E-06
4.93E-06
2.87E-06
1.68E-06
9.76E-07

Each method found the root to fie significant figures but


with a varying number of steps. The accuracy was
achieved in:
34 iterations for the change in sign method
5 iterations for the newton Raphson method
23 iterations for the x = g(x) method
Comparing all three methods, the newton Raphson
method worked a lot faster to find out the root to the
18

Joseph Wheatland

same accuracy as the other methods in this particular


example. The change of sign method was the slowest
but the easiest to understand while x = g(x) was in the
middle of the other two for speed and is also difficult to
do compared to the change of sign method. The x =
g(x) and newton Raphson methods are more tasking
but were much quicker in getting the required
accuracy, but the x = g(x) method was still a deal
slower than the newton Raphson.
The easiest method by far was the change in sign, as it
didnt require software for ease of use and you could
keep narrowing it down to a high accuracy. This method
requires a lot of work to do in spreadsheet software
involving formula manipulation but the ease of use and
little understanding required, give this method good
merit.

The newton Raphson method was rather slow to do by


hand and rounding errors occurred. However with the
help of the autograph software and excel the results
were very easy to achieve as the computer could
repeat the iterations with ease. The method does
require being able to differentiate though so it is one of
the more difficult methods. The general formula means
all that is required is a reasonable estimate for the root
which lays near the intersection of the x axis you are
searching for. As the answers can be substituted each
time it doesnt vary too much, although it is time
consuming if software isnt available to you.

19

Joseph Wheatland

The x = g(x) method is also not too difficult as it only


requires the ability to rearrange f(x) = 0. This method
converges faster than the decimal search method but
slower than the newton Raphson. It can take a long
time to converge though as not all rearrangements of
the equation into g(x) form would be suitable. If
spreadsheet software was available then the time
consuming convergence issue would not occur.
If only spreadsheet software was available then the
easiest method to use would be the change in sign as
the rows can be auto completed once the general
formula is interpreted. It is easier to spot if an error has
occurred too. But without software it is possible for the
user to overlook the possibility of more than one sign
change in an interval. Autograph is a helpful factor in
the x = g(x) method especially as just from looking at
the steepness of the rearranged curve compared to y =
x suggests if the outcome will converge, diverge,
staircase or cobweb. The visualisations that graphing
software provide for the newton Raphson method too
means that you can tell if the particular equation is
going to work early on.

20

Vous aimerez peut-être aussi