Web Lesson 33: Iteration

Iteration

Iteration in an ‘indirect method’ of solving an equation

That means it does not give an exact answer, but it can be used to give an approximate answer to an equation

The level of accuracy is determined by how many iterative steps are used

To use iteration to solve an equation:

  1. You need an iteration algorithm (i.e. an equation with ‘xn+1’ on the left hand side, given in terms of ‘xn’)
  2. You need a starting point (called x0)
  3. You need to refine your answer (this means finding: x1, x2, x3 etc.)
  4. You need to know when to stop iterating (i.e. what level of accuracy you require your answer to).

e.g. In order to solve x³ + 5x – 10 = 0, use the algorithm:
 			xn+1 =	  10    .
				xn² + 5
 
starting with x0 = 1 to work out x1, x2, x3, x4 & x5
  • If we put ‘n=0’ into the algorithm, we get:
    x1  =	   10   
    	x0² + 5		
     
    And, since we know x0 = 1:  
     
    x1  =	   10   	=	   10   	=	1.66666666 (from calc.)
    	x0² + 5			(1)² + 5
    				
    	└ ------- x0 = 1 ------	┘ 
     
  • Next, we put ‘n=1’ into the algorithm, we get:
    x2  =	   10   	=	      10     	=	1.285714286 (from calc.)
    	x1² + 5			(1.66..)² + 5
    				
    	└ --- x1 = 1.66.. -----	┘ 
     
  • Next we put n = 2:
    x3  =	   10   	=	      10     	=	1.503067485 (from calc.)
    	x2² + 5			(1.28..)² + 5
    				
    	└ --- x2 = 1.28.. -----	┘ 
     
  • Then n = 3:
    x4  =	   10   	=	      10     	=	1.377560015 (from calc.)
    	x3² + 5			(1.50..)² + 5
    				
    	└ --- x3 = 1.50.. -----	┘ 
     
  • And, finally, n = 4:
    x5  =	   10   	=	      10     	=	1.449764586 (from calc.)
    	x4² + 5			(1.37..)² + 5
    				
    	└ --- x4 = 1.37.. -----	┘ 
     

Now, if I tell you that one solution of the equation x³ + 5x – 10 = 0 is x = 1.423318345, then you can see that our answers have been getting closer to this solution. We say that our iterations will "converge" towards this answer (although it will take a few more iterations (repeats) to get there...)


Question 1: Starting with x0 = 4 and using the algorithm:
			xn+1 = √(25 - ln xn)
 
Find x1, x2, x3, x4 and x5 
Clue:
 
n=0:			x1  = √(25 - ln x0)	= √(25 - ln 4)		=  4.859393546  (from calc.)
 
n=1:			x2  = √(25 - ln x1)	= √(25 - ln 4.859...)	=  ......       (from calc.)
 
n=2:			x3  = √(25 - ln x2)	= √(25 - ln ......)	=  ......       (from calc.)
 
n=3:			x4 = ....
 
n=4:			x5 = 4.83974....
 
Notice that this series converges a lot quicker than the example above
(i.e. the answers are a lot closer together)
 
 
Question 2: Starting with x0 = 2 and using the algorithm:
			xn+1 = ³√(14 - xn²)
 
Find x1, x2, x3, x4 and x5 
Clue:
 
n=0:			x1 = ³√(14 - x0²)	= ³√(14 - 2²)		= 2.15443469  (from calc.)
 
n=1:			x2 = ³√(14 - x1²)	= ³√(14 - 2.154...²)	= ....        (from calc.)
 
Etc...
 

Finding an Algorithm

Like the ones above, most questions will give you algorithm; so this whole stage can be skipped...

But, if the algorithm isn't given, then there are usually four different algorithms that can be produced to solve the equation.

In an exam question, you will be told which one they want you to produce, but here I will show you how to produce all four...

To illustrate to this process, I will try to find four different algorithms to solve: x³ + 5x – 10 = 0:

  1. Pick any one of the ‘x’s in the equation and make that the subject of the equation
    (it does not matter that the other ‘x’s are left on the other side)

    So, if I pick the ‘x’ next to the ‘5x’: x³ + 5x – 10 = 0
     
    (add ‘10’): 				x³ + 5x = 10
     
    (subtract ‘x³’):			     5x = 10 – x³
     
    (divide by ‘5’):		 	      x = 10 – x³
    					             5
     
  2. Add a subscript of ‘n+1’ to the ‘x’ that is now the subject (so it becomes: xn+1)
    Add a subscript of ‘n’ to the ‘x’s on the other side of the equation (so they become: xn)

    					     x = 10 – x³
    					            5
    
    So, we get: 				   xn+1 = 10 – xn³
    					            5    .
     
  3. Of course, I had a choice of which x to make the subject...
    If I had chosen a different ‘x’ I’d have a different algorithm

    If I had chosen the x in the ‘x³’:	x³ + 5x =   10
     
    (subtracting ‘5x’):			x³      =   10 – 5x
    
    (cube-rooting):				x       = ³√10 - 5x
    
    (add the subscripts):			xn+1    = ³√10 - 5xn 
     
  4. A way of getting two more algorithms is to:

    • Collect all of the x’s to one side:
      x³ + 5x = 10
       
    • Factorise:
      x(x² + 5) = 10
       
    • Make one of these x’s the subject:
      Making this x the subject: x(x²+5)=10	  │	Making this x the subject: x(x²+5)=10
      					  │
      	x(x² + 5) =     10		  │		x(x² + 5) = 10
              ÷(x²+5)     ÷(x²+5)		  		÷x          ÷x
      	-------------------		  		------------------
      	x         =     10  .		  │		  x² + 5  = 10
      	              x² + 5		  │		             x
       					  │		      -5         - 5
      	xn+1      =     10   .-----------------------
      	             xn² + 5		  │		  x²      = 10/x - 5
      					  │		  √         √
      					  		-----------------------
      					  │		  x       = √(10/x - 5)
      					  │
      					  │		  xn+1     = √(10/xn - 5)
       
                              
Question 3: Find 4 different algorithms for solving: x³ - 2x - 5 = 0
Clue:
 
1st algorithm: Make this x the subject:		 x³ - 2x - 5 =    0
						 x³          =    2x + ..
						 x           = ³√(2x + ..)
 
Add subscripts:					 xn+1        = ³ √(2xn + ..)	. . . . . . alg (1)
 
2nd Algorithm: Make this x the subject:		 x³ - 2x - 5 = 0
						 x³      - 5 = 2x
						 ½(x³ - ..)   = x
 
Add subscripts:					 ½(xn³ - ..)  = xn+1  		. . . . . . alg (2)
 
Now, to get any more algorithms, we must first: Collect the x terms to one side and factorise:
						 x³ - 2x     = 5
						 x(x² - 2)   = 5
 
3rd Algorithm: Make this x the subject:		 x(x² - 2)   = 5
						 x           =     5    
						                x² - ..
 
Add subscripts:					 xn+1        =      5    	. . . . . . alg (3)
						                xn² - ..
 
4th Algorithm: Make this x the subject: 	 x(x² - 2)   = 5
						   x² - 2    = 5/x
						   x²        = ......
						   x         = √(......)
 
Add subscripts:					   xn+1      = √(......)  	. . . . . . alg (4)
 

Note: Exam questions often give us the algorithm and ask us to show that it is correct. This very easy:

  1. Remove the subscripts
  2. Show that this re-arranges to the equation we want to solve

e.g. Show that xn+1 = √(xn + 6/xn) is an algorithm to solve: x³ - x² - 6 = 0
Clue: (remove subscripts): 		          x = √x + 6/x 
 
(re-arrange: square): 			         x² = x + 6/x
 
(re-arrange: multiply by x): 		         x³ = x² + 6
 
(re-arrange: move terms): 		x³ - x² - 6 = 0
 
 
Question 4: Show that xn+1 = 4e-xn is an algorithm to solve: xex = 4
Clue: (remove subscripts): 			  x = 4e-x
 
(re-arrange: multiply by ex): 			... = ..
 
 
Question 5: Show that xn+1 = ³√(14 - xn²) is an algorithm to solve x³ + x² - 14 = 0

 

Finding a Starting Point: Called: x0

  • Most questions will give you a starting point. i.e. "find the solution near x=1" means that x0 = 1

  • However, if no starting point is given, then either one of these methods can be used to find one:

    1. Finding a value of x that, when put into the equation, almost makes both sides equal. Call this value, ‘x0
    2. Use the graphical solutions method (very rough sketch graphs will do) to find an approximate solution. Call this, ‘x0
  • Sometimes a slightly different starting point will make an algorithm work

 

Refining your Estimate

Now that we have a starting point, we can use the algorithm to improve our estimate:

The algorithm works like this: When we put x0 (starting guess) into it, the answer is called x1 (1st improvement)

And then, when we put x1 back into the algorithm, the answer is called x2 (2nd improvement)

Etc...

Going back to the first example we did (at the start of this web lesson)

e.g. In order to solve x³ + 5x – 10 = 0, use the algorithm:
 			xn+1 =	  10    .
				xn² + 5
 
starting with x0 = 1 to work out x1, x2, x3, x4 & x5
  • If we put ‘n=0’ into the algorithm, we get:
    x1  =	   10   	=	   10   	=	1.66666666 (from calc.)
    	x0² + 5			(1)² + 5
    				
    	└ ------- x0 = 1 ------	┘ 
     
  • Next, we put ‘n=1’ into the algorithm, we get:
    x2  =	   10   	=	      10     	=	1.285714286 (from calc.)
    	x1² + 5			(1.66..)² + 5
    				
    	└ --- x1 = 1.66.. -----	┘ 
     
  • Next we put n = 2:
    x3  =	   10   	=	      10     	=	1.503067485 (from calc.)
    	x2² + 5			(1.28..)² + 5
    				
    	└ --- x2 = 1.28.. -----	┘ 
     
  • Then n = 3:
    x4  =	   10   	=	      10     	=	1.377560015 (from calc.)
    	x3² + 5			(1.50..)² + 5
    				
    	└ --- x3 = 1.50.. -----	┘ 
     
  • And, finally, n = 4:
    x5  =	   10   	=	      10     	=	1.449764586 (from calc.)
    	x4² + 5			(1.37..)² + 5
    				
    	└ --- x4 = 1.37.. -----	┘ 
     
     

Knowing when to Stop

  • If we require an answer to 2.d.p, then:

  • As we work out x1, x2, x3 ..., we write a table of the exact values as well as giving them to 2 d.p.
    So, for the example above:

    xn Exact Value 2 d.p.
    x1 1.66666666 1.67
    x2 1.285714286 1.29
    x3 1.503067485 1.50
    x4 1.377560015 1.38
    x5 1.449764586 1.45

  • You can stop iterating when the answer in the ‘2 d.p.’ column repeats.
    So, for the example above, if we carry on with the iterations:

    xn Exact Value 2 d.p.
    x1 1.66666666 1.67
    x2 1.285714286 1.29
    x3 1.503067485 1.50
    x4 1.377560015 1.38
    x5 1.449764586 1.45
    x6 1.408090282 1.41
    x7 1.432107047 1.43
    x8 1.418252508 1.42
    x9 1.426240508 1.43
    x10 1.421633454 1.42
    x11 1.424290078 1.42

  • So, a solution to x³ - 5x + 10 = 0 is: "x = 1.42 (2.d.p.)"
     

Question 6: Show that xn+1 = ³√6 + xn² is an algorithm for solving x³ - x² - 6 = 0
Given that a root exists near x=2, find this root giving your answer to 2 d.p.
Clue: Since we are given the algorithm [xn+1 = ³√6  + xn²] for the equation, we can work backwards:
 
(remove the subscripts): 		          x = ³√6 + x²
 
(re-arrange: cube): 			          x³ = .. + ..
 
(re-arrange: swap terms): 		x³ - .. - .. = 0
 
So, now we can use the algorithm, starting with x0 = 2
 
Putting '2' into the equation:				x1 = ³√6 + 2² 		= 2.15443469
Putting '2.1544...' into the equation:			x2 = ³√6 + 2.1544...² 	= 2.199558371
Putting '2.1995...' into the equation:			x3 = ³√6 + 2.1999...² 	= ...........
Etc....
                
xn Exact Value 2 d.p.
x1 2.15443469 2.15
x2 2.199558371 2.20
x3 2.213012213 2.21
x4 2.17045488 ...
x5 ... ...
x6 ... ...
x7 ... ...
 
 
So, the answer is ...... (2.d.p)

 
Question 7: An algorithm to solve x4 - 5x - 5 = 0 is of the form: xn+1 = 4B + Axn 
Find the values of 'A' and 'B'
Given that a root exists near x=2, find the root to 4.d.p. 
Clue: Let's just try and find a few algorithms in the normal way and then see if any look like
      the one they want:
 
So, lets make this x the subject: x4 - 5x - 5 = 0 ....
[Does the answer look like theirs? Yes! Then what are 'A' and 'B']
 
Now lets start with x0 = 2
Putting x0=2 into the algorithm:			x1 = 45 + 5(2)  	=  1.96798671
Putting x1=1.96... back into the algorithm:	x2 = 45 + 5(1.96...) 	=  1.962718868
And tabulating our results as we carry on:
 
xn Exact Value 4 d.p.
x1 1.96798671 1.9680
x2 1.962718868 1.9627
x3 ... 1.9618
x4 ... ...
x5 ... ...
 
 
So, the answer is 1.961- (4.d.p)
 
 
Question 8: An algorithm to solve ex - 3x = 0 is of the form xn+1 = ln (Axn)
Find 'A'
Sketch the graph of y = ex and y = 3x on the same grid and find the integer value of x near where they intersect. Using this as your starting value for the iteration, solve the equation ex - 3x = 0 giving your answer to 2 d.p.
Clue: Make this x the subject: ex - 3x = 0
 
You should have no problems sketching the graphs and seeing that they meet near x=2
 
Starting with x0 = 2				x1 = ln (3×2) 		= 1.7917...
						x2 = ln (3×1.7917)	= ...
Tabulating the answers as you go...
 
 
Question 9: Show that: xn+1 = 1/(xn²+2) and xn+1 = √(1/xn - 2) are both algorithms for: x³ + 2x - 1 = 0
Starting with x0 = 0.4, show that one of these algorithms converges to a root whereas the other does not.
Give this root to 3.d.p.
Clue: It is easy to show that: xn+1 = 1/(xn²+2) is an algorithm:
(remove subscripts): 				          x = 1/(x²+2) 
(re-arrange: multiply by 'x²+2'): 		 ......     = 1
(re-arrange: expand):				.. + ..     = 1
(re-arrange: shift terms): 			.. + .. - 1 = 0
 
It is similarly easy to show xn+1 = √(1/xn - 2) is an algorithm...
 
Using the first algorithm and starting with x0 = 0.4:
x1 = 0.462962963
x2 = 0.451602911
x3 = ...
 
Using the second algorithm and starting with x0 = 0.4
x1 = 0.707
x2 = ERROR
 
So the second algorithm does not converge!
 

Note: This is often the case with iteration. One algorithm may converge towards the root, but another may not!
 

Question 10: Find an algorithm to find the root of x³ - 2x - 5 = 0 Try using your algorithm to find the root of the equation near x=2 If your algorithm doesn't converge to give an answer to 3 d.p. within 10 iterations, then find a different algorithm and try that...

Hand in your answers next lesson