title: How to graph an iteration method?
body: <p>In the following code I have implemented the bisection method in Python. Just as a general overview my code does the following:</p>
  
  <ul>
  <li>My function is able to find the root of an arbitrary continuous scalar valued function f as a lambda function a prescribed function tolerance. </li>
  <li>My routine finds the root of the function f(x) = cos x - sin x on the interval [0,1] with tolerance 10^{-14} </li>
  <li>Records how many iterations it takes to reach this tolerance.</li>
  </ul>
  
  <p><strong>However now I am looking to plot the convergence diagram on that same interval. This would be the absolute error as a function of the number of iterations.</strong></p>
  
  <p>To do this I must collect the series of error figures in a list, and plot that against a list of the integers 1 through your final value of iter.</p>
  
  <p>I am looking for some help with this as I am stuck. I have made another 2 codes with different iteration methods so once I can see how it works on this one I should be able to implement it on the others also! All help is greatly appreciated</p>
  
  <pre><code>import math
  def root(x):
      return(math.cos(x)-math.sin(x))
  
  def bisection_method(f, a, b, tol):
      if f(a)*f(b) &gt; 0:
          #end function, no root.
          print("No root found.")
      else:
          iter = 0
          while (b - a)/2.0 &gt; tol:
              midpoint = (a + b)/2.0
  
              if f(a)*f(midpoint) &lt; 0: # Increasing but below 0 case
                  b = midpoint
              else:
                  a = midpoint
  
              iter += 1
          return(midpoint, iter)
  
  answer, iterations = bisection_method(root, 0, 1, 10**(-14))
  print("Answer:", answer, "\nfound in", iterations, "iterations")
  </code></pre>