3

enter image description here

I am trying to help prepare a friend for a midterm coming up and this is one of the question on a practice midterm of 5 years ago. To be honest I have trouble recalling some of the topics of Numerical Analysis. I believe the method to use would be the Bisection method but I forgot how to use it and the book is very tricky to follow.

Stan-Lee
  • 131

1 Answers1

5

Bisection is a good choice for part a. It is simple to use and converges linearely. I will here show how to use the bisection-method to find a root, i.e. a point $x$ satisfying $f(x) = 0$, of any given (continuous) function.


${\bf Setup}$: Given a function $f$, first find a point $x_{\rm high}$ where $f(x_{\rm high}) > 0$ and then a point $x_{\rm low}$ where $f(x_{\rm low}) < 0$. Since the function is continuous we know from the intermediate value theorem that there must be a root between $x_{\rm low}$ and $x_{\rm high}$.

${\bf The~method}:$ We start by investigating the midpoint $x_{\rm mid} = \frac{x_{\rm high} + x_{\rm low}}{2}$. If $f(x_{\rm mid}) > 0$ then the root has to be between $x_{\rm low}$ and $x_{\rm mid}$ so we take $x_{\rm high}^{\rm (new)} = x_{\rm mid}$. If $f(x_{\rm mid}) < 0$ then the root has to be between $x_{\rm mid}$ and $x_{\rm high}$ so we take $x_{\rm low}^{\rm (new)} = x_{\rm mid}$. Having determined the new value of $x_{\rm low}$ or $x_{\rm high}$ we can compute a new $x_{\rm mid}$ and repeat the procedure above until we have determined the solution to sufficient accuracy.


${\bf Determining~the~accuracy}$: The distance between $x_{\rm low}$ and $x_{\rm high}$ halves for each itteration so after $n$ steps we will have

$$|x_{\rm high}^{(n)}-x_{\rm low}^{(n)}| = \frac{|x_{\rm high}^{(0)}-x_{\rm low}^{(0)}|}{2^n}$$

Since we always know that the solution is between the high and the low value we know that

$$|x_{\rm true} - x_{\rm high}^{(n)}| < \frac{|x_{\rm high}^{(0)}-x_{\rm low}^{(0)}|}{2^n}$$

so by taking $n$ large enough we can get as close as we want to the true solution.


For your acctual example we can take $f(x) = x^3 - 2.179$ as the function since $f(x) = 0 \implies$ $x^3 = 2.179$. We see that $f(0) < 0$ and $f(2) > 2$ so we can take $x_{\rm low} = 0$ and $x_{\rm high} = 2$. After $n$ itterations the accuracy of our solution will be better than

$$\frac{2-0}{2^n} = \frac{1}{2^{n-1}}$$

and if $n\geq 18$ the term above will be smaller than $10^{-5}$.


If you prefer reading code, the algorithm above can be described by the following pseudo code:

// The function we are trying to find the zero of
function(x) : x^3 - 2.197

// Initial guess (where xlow < xsolution and xhigh > xsolution)
xlow  = 0.0
xhigh = 2.0
accuracy = 10^-5

// Bisect until the zero is found to given accuracy
while(xhigh - xlow > accuracy ) {

   // Compute midpoint
   xmid = (xlow + xhigh)/2

   // Compute function value at midpoint
   if( function(xmid) > 0.0 ){
     // xmid is larger than the true solution so take this as new xhigh
     xhigh = xmid
   } else {
     // xmid is smaller than the true solution so take this as new xlow
     xlow = xmid
   }
}

${\bf Newtons~method}$: For the second part of the problem I would suggest Newton's method. It is, after bisection, the simplest method to use and it converges quadratically as desired.

The method is quite simple: given a differentiable function $f(x)$ we can find a zero by itterating the recursion

$$x_{n+1} = x_n - \frac{f(x_n)}{f'(x_n)}$$

from an initial guess $x_0$. Since we already know that the root is in $[0,2]$ taking $x_0 = 1$ seems like a good choice; this does not matter all that much but the closer we start the faster it will converge. There are some conditions that have to be met if convergence is to be guaranteed with Newton's method, see this page for more info. The function $f(x) = x^3 - 2.719$ satisfy these conditions.

Winther
  • 24,478