One of the questions in Example ex:sqrt:65 asked to write down the steps to find the square root. Throughout this book and in many related fields, like computer science, reproducing results in a specific ways is immensely important. We call this an algorithm.
The next example shows that we actually use algorithm in our daily lives. This is a short cooking example, but finding directions or navigating webpages are other good examples of using algorithms.
The next example shows the algorithm that can be used to find \(\sqrt{65}\) as in Example 2.1.1. This is called the bisection method and we will see the details of the algorithm in Chapter 3—in short it starts with an interval that always contains the answer and through a procedure, finds subintervals that still contains the answer and the length of the subinterval shrinks.
In this case, we will produce a sequence of numbers \(a_{0},a_{1},a_{2},\ldots\) that are always below\(\sqrt{a}\) and \(b_{0},b_{1},b_{2}, \ldots\) that are always above\(\sqrt{a}\text{.}\) The algorithm is listed below and sentences in italics are simply comments.
If \(a \gt 1\text{,}\) then \(a_{0}=1\) and \(b_{0}=a\text{.}\) If \(a \lt 1\) then \(a_{0}=a\) and \(b_{0}=1\text{.}\)This ensures that \(\sqrt{a}\in [a_{0},b_{0}]\text{.}\)
The next example shows how to employ a spreadsheet to run through the algorithm in Example 2.2.4. Computers are a great tool to automate algorithms and spreadsheets as well as other tools such as Maple, Mathematics, Matlab or programs written in other languages are how a lot of mathematics are done.
In this case, we will use a spreadsheet to accomplish this. We will make three columns (A, B, C) for the three sequences \(a_{n}, b_{n}\) and \(c_{n}\text{.}\)
Since \(a=65 \gt 1\text{,}\) we will put a 1 in the first row of column A and a 65 in the first row of column B. For column C, enter =0.5*(a1+b1) and you should get 33. Also, create a column (in D) that will be the error. Enter in cell D1, =b1-a1.
For the next row, we enter step 4 from Example ex:sqrt in the spreadsheet. For cell A2, enter =IF(C12 > 65,A1,C1). This will fill in either the mean (in column C) or the value above it. For cell B2, enter =IF(C12>65,C1,B1).
To continue this, you can select the four columns in the second row, click on the lower right corner and drag down an number a places. The spreadsheet will fill in the values in a recursive manner.
In the 17th row, you will see that the error (in the last row) is now smaller than 0.001, so you should stop. The approximation to the \(\sqrt{65}\) is 3.06201, which is correct to 3 digits.
In this case, we will use a spreadsheet again. The first column will be \(n\) and the 2nd column will be \(x_{n}\text{.}\) In the first row, enter \(0\) and \(65\text{.}\) In the second row enter =a1+1 and =b1/2+65/(2*b1). Select these two cells and in the bottom left corner, drag down a number of rows. You should see:
Subsection2.2.2YASRA: Yet Another Square Root Algorithm
We will use Taylor’s series (see Section 1.6) for \(f(x)=\sqrt{x}\) to find another algorithm for the square of \(a\text{.}\) Let \(c\) be the center of the Taylor’s Series of a function \(f(x)\text{.}\) Then the function can be written
where \(n!!=1\cdot 3 \cdot 5 \cdot 7 \cdots n\) and this is similar to Example 1.6.11, but in that example, the center was \(0\) and for this the center of the series is \(c\text{.}\)
In this section, we have seen three different ways to compute a square root. Each produces a sequence of points. Here are some of the questions we should ask: