Mathematics 162                              Laboratory 9                          Week of March 29, 1993
	  
Name: _____________________________   Lab Partner: ___________________________
	  
Consulted with:  ____________________________________________________________

© Lafayette College, 1994.

Approximating Functions with Polynomials

Problem:  Given a function f(x) and a point x = a, find a polynomial, p(x), which approximates f(x) near x = a.

The general idea behind our approach is that if f (x) is a given function and the polynomial p(x) is chosen so that the function and all its derivatives have the same value as f and its derivatives at x = a, then p(x) should agree pretty well with f(x).  After all, we will have p(a) = f (a), the graphs of p and f will be tangent to the same line at x = a, the graphs will have the same concavity at x = a, and so forth.

Since we are interested in approximating our function f (x) for values of x near a, it makes sense to express our approximating polynomial in powers of x – a, rather than powers of x.  Thus our polynomial will be of the form

All we have to do is determine the values of the coefficients c0, c1, c2, ..., cn so that the polynomial and its derivatives have the same value as the function at a.

Part 1: Approximate with quadratic polynomials

Define the function

f[x_] := Sqrt[x]

We will approximate f near x = 1 with a 2nd degree polynomial.  Based on the discussion above, we should find an approximating polynomial of the form

poly[x_] := c[0] + c[1] (x-1) + c[2] (x-1)^2

where the c's are chosen so that the following equations hold:

equations :=
 {f[1]==poly[1],f'[1]==poly'[1],f''[1]==poly''[1]}

We wish to solve these equations for the c's, so we will define them to be the solutions:

solutions := {c[0], c[1], c[2]}

To find the appropriate values, we can use the Solve command:

Solve[equations, solutions]

To define our approximating polynomial we can enter

p2[x_] = poly[x] /. %

Write down the definition of p2(x) below, along with the values of the function and its first and second derivatives at x = 1.  Compare them with the corresponding values of f.  Do they actually agree?

p2(x) = 
 
p2(1) =                                                         f (1) =

p'2(1) =                                                        f '(1) =
  
 p''2(1) =                                                      f ''(1) =

To see how well p2(x) approximates f (x) for x near 1, plot a graph:

Plot[{f[x],p2[x]}, {x,0,2}, PlotStyle -> {Red,Blue}]

Based on your graph, over what interval is the polynomial a good approximation for the square root function?

Part 2: Approximate with bigger polynomials

A higher degree polynomial should give a better approximation of our function.  Implementing this is not conceptually harder than Part 1, but using the procedure in Part 1 to create an approximating polynomial of degree 30, say, would involve a lot of typing.  We will cut down on that typing by using Mathematica's Sum and Table commands.  First,

Clear[poly, equations, solutions]

so that we will be ready to start a new approximation.  Now, define

poly[x_] := Sum[ c[j] (x-a)^j, {j, 0, n}]

so our approximating polynomial will have the form shown on the first page.  The system of equations which determine the coefficients in poly[x] is

equations := Table[
(D[f[x],{x, k}] /. x->a)==(D[poly[x],{x, k}] /. x->a),
             {k, 0, n}]

with solutions

solutions := Table[c[m], {m, 0, n}]

From here, we should be able to choose a value a to approximate at, and a degree n for the aproximating polynomial and then use Solve to create the approximating polynomial.  Check the new procedure by letting

a = 1

n = 2

Repeat the procedure of Part 1:

Solve[equations, solutions]

p2[x_] = poly[x] /. %

Now, let n = 3 to generate a 3rd degree approximating polynomial p3(x).  Write your result below:

p3(x) =

Now, follow the same steps to generate a 4th-degree polynomial which approximates our function.  Write it below:

p4(x) =

To compare all these polynomials, plot their graphs together:

Plot[{f[x], p2[x], p3[x], p4[x]}, {x, 0, 3},
    PlotStyle -> {Red, Blue, Green, Black}]

Write a couple of sentences describing the apparent accuracy (or inaccuracy) of the approximations.

Join[{{"x"," ","Errors"," "},{"Value","p2","p3","p4"}},
Table[{x, f[x]-p2[x], f[x]-p3[x], f[x]-p4[x]},
    {x,0.5,1.5,0.1}]]

Notice that for x = 1, all of the errors are equal to 0.  Explain why this is the case.  For x = 1.2, approximately how much extra accuracy do we gain when we increase the degree of the approximating polynomial by one?

Part 3:  Approximate the arctan function

Let

f[x_] := ArcTan[x]

We will find polynomials which approximate this function using the same procedure we used in Part 2.  Because of the way we defined poly, equations, and solutions, we do not need to Clear or redefine these here.

Create the 7th degree approximation of arctan near x = 0.  For what values of x does this polynomial seem to give a good approximation of f (x)?  (You might look at a plot over the interval [–2,2].)  Explain your answer.

How good is this polynomial's approximation of f(-0.5)?  of f(1)?  of f(1.5)?  Explain your answers, being as quantitative as possible.

Obtain a 7th degree approximation of f near x = 1 and use it to estimate tan–1(1.5).  What is the error in this estimate?

tan–1(1.5) is about:                                               error in this estimate is:

Does this polynomial give a good approximation of tan–1(–0.5)?  What is the error in this estimate?

If you wanted to estimate tan–1(–0.5), would you use the first or second polynomial?  Which polynomial would you use to estimate tan–1(1.5)?