Numerical Analysis 1

Spring 2005

Format

Lecture

Most classes will consist of lectures, question and answers, problem solutions, and presentation of examples.  Much of the presentation will be computer-based.

Procedures used in a number of computations will be the focus of the class.

This will not be a theoretical course but will be more mechanical in the sense of 'hands-on' dealings with numerical analysis techniques.  Examples of computations will be shown, and pitfalls accompanying the methods will be pointed out--Generally, proofs of the methods will not be discussed.

Computer Oriented using the Mathematica Computer Package

Many Computer Packages are Available

The major computer packages for doing mathematics are Maple, Mathematica, and Matlab.  Even though your textbook is written in terms of the Matlab Computer Package, we use Mathematica because (1) Mathematica is available in all campus computer laboratories; (2) The author of your textbook has written and made available Mathematica notebooks paralleling the Matlab routines discussed in the book (the link shown above is the first of such notebooks); (3) I have been a Mathematica user since it came out in 1988, and am most familiar with this package.

From the preface to Stan Wagon's book Mathematica in Action

"... a computational way of looking at a mathematical problem or result yields many benefits.  For example:
--Well-chosen computations can shed light on familiar relation sand reveal new patterns
--One is forced to think very precisely about the problem; any gaps in understanding must be eliminated if a program is to work.
--Dozens (or even hundreds) of cases can be examined, perhaps showing new patterns or phenomena.
--Methods of verifying the results must be work out, again adding to one's overall understanding of a problem.
--Different proofs of the same theorem can be compared from the point of view of algorithmic efficiency"

Introduction to Mathematica and Chapter 1

Mathematica Fundamentals

Notebook Format

Help Browser

A Look at Mathematica Capability

Overview of Numerical Analysis Topics

Mathematical Techniques

A short review of calculus topics is given in Section 1.1.  You can download the Mathematica materials on these techniques from the following link.  The link will take you to your class webpage (from that webpage point to titled Mathematica File for Chapter 1, hold down the right mouse button and choose the option save the file to your computer. Once the download finishes open the copy of MathReader [or Mathematica, if you have it] on your computer and once open, open the downloaded file from within MathReader [or Mathematica]).

Link to Mathematica Materials for Chapter 1

Horner's Method

Horner's Method

Horner's Method Computations

Horner's method works by factoring a polynomial in a certain way and then iterating simple additions and multiplications on the resulting form.  For example, the polynomial 2(x^3)+ 3(x^2)+ x + 1 = (x^2)(2x+3) + x + 1 = x(x(2x+3)+1)+1.  Horner's method works from the 'inside out', that is, the steps in evaluating this at x=2 are first to find the value of 2x+3 when x=2, i.e,. 7, then to find x7+1 when x=2, i.e. 15, and finally find x15+1 at x=2 or 31.  This last number is the value of the polynomial when x=2 as is verified by the Mathematica syntax on the next line.

2  (x^3) + 3  (x^2) + x + 1 /. x -> 2

Notice from the last example that you start with the coefficients of the polynomial to be evaluated in the order from largest to smallest, that is the list 2,3,1,1.  You start by evaluating 2x+3 when x=2, you then take this result multiply by 2 and add the next coefficient, etc.  Now, the same process is carried out in Mathematica notation.  First the coefficients of the polynomial are entered in a list.

amat = {2, 3, 1, 1}

To make the process 'fit' Mathematica's format or the recursive step discussed above, the matrix is reversed

amat = Reverse[amat]

The polynomial will be evaluated at c=2.  This is entered, as follows, into Mathematica.

c = 2

The recursive step given at the bottom of page 10 in your textbook is shown next.  The notation amat[[k]] takes the kth element of list or matrix amat.

newb[k_] := amat[[k]] + c*newb[k + 1]

The starting value for the newb list or matrix is 1, and this is entered into Mathematica in the following statement.

newb[4] = 2

The next statement performs the looping shown at the bottom of page 10 of your textbook.  The Mathematica notation finds newb[3], then newb[2], etc., down to newb[1].

Table[newb[k], {k, 3, 1, -1}]

The last result in the output list is the value of the polynomial at 2.

Now suppose that you would like to evaluate the polynomial (x^6) + 4(x^5)- 6(x^4)+ 8(x^3)+ 8(x^2)+ 4x - 40 using Horner's Method at x=1.  Following the same steps as above:

amat = {1, 4, -6, 8, 8, 4, -40}

amat = Reverse[amat]

c = 1

newb[7] = 1

Table[newb[k], {k, 6, 1, -1}]

The Mathematica evaluation of the polynomial at 1 is shown in the following, and it is agrees with the result that we developed.

(x^6) +4(x^5)-6(x^4)+8(x^3)+8(x^2)+4  x-40/.x -> 1

The following is a construction of a 'Horner's Method Function' with inputs the list of coefficients of the polynomial and the x-value for which the polynomial is to be evaluated.

hornereval[coefflist_List, 
        xval_] := 
Module[{amat, 
          newb}, 
amat = 
          Reverse[coefflist]; 
newb = 
          amat; 
Table[
          newb[[k]] = amat[[k]] + xval* newb[[k + 1]], {k, 
            Length[amat] - 1, 
            1, -1}]; 
newb[[1]]
]

Using the just constructed function to evaluate (x^6) + 4(x^5)- 6(x^4)+ 8(x^3)+ 8(x^2)+ 4x - 40 at -30, -29, -28,...,0, 1, 2,...,30 and timing the process results in the following.

Timing[
      Table[hornereval[{1, 4, -6, 8, 8, 4, -40}, k], {k, -30, 
          30}]]

Using the built-in Mathematica syntax for the same evaluation results in the following timing.  Note that Mathematica is faster.

Timing[
      Table[(x^6) + 4  (x^5) - 6  (x^4) + 8  (x^3) + 8  (x^2) + 4  x - 
            40 /. {x -> k}, {k, -30, 30}]]